Click here to Skip to main content
16,007,760 members
Home / Discussions / C#
   

C#

 
GeneralRe: Rich text background colour/selection Pin
Dave Kreskowiak28-Jun-05 5:41
mveDave Kreskowiak28-Jun-05 5:41 
GeneralRe: Rich text background colour/selection Pin
IJay28-Jun-05 5:49
IJay28-Jun-05 5:49 
GeneralRe: Rich text background colour/selection Pin
mav.northwind28-Jun-05 6:05
mav.northwind28-Jun-05 6:05 
GeneralRe: Rich text background colour/selection Pin
IJay29-Jun-05 5:41
IJay29-Jun-05 5:41 
GeneralRe: Rich text background colour/selection Pin
mav.northwind29-Jun-05 19:57
mav.northwind29-Jun-05 19:57 
GeneralRe: Rich text background colour/selection Pin
IJay29-Jun-05 22:18
IJay29-Jun-05 22:18 
GeneralRe: Rich text background colour/selection Pin
IJay29-Jun-05 23:43
IJay29-Jun-05 23:43 
GeneralMy TcpListener doesn't works Pin
Alex Cutovoi28-Jun-05 3:27
Alex Cutovoi28-Jun-05 3:27 
Hi for all

I created an application to connect to my client to play NavyBattle.
When the application run, it's locked when the Socket is receiving the socket sended by method AcceptSocket of TcpListener. The application' s form doesn't show. I saw the taskmanager processes, and it's there.

Can someone aswer my question?

The code are below:



using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Net;
using System.Net.Sockets;
using System.IO;

namespace TcpNavyBattle
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Label ConnexionLabel;
private System.Windows.Forms.TextBox TxtLocation;
private bool bConnected;
private Server m_Player1;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;

public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
Server Player1 = new Server();
m_Player1 = Player1;
//Player1.Running();
//bConnected = Player1.IsConnected();
//
// TODO: Add any constructor code after InitializeComponent call
//
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#Code generated by Visual Sutdio
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}

protected void TxtLocation_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
if(bConnected)
{
if(e.KeyCode == Keys.Enter && TxtLocation.Text != null)
{
ConnexionLabel.Text = "Value inserted";
m_Player1.Write(TxtLocation.Text);
}
else
{
ConnexionLabel.Text = "Connection closed or textbox is null";
}
}
else
{
MessageBox.Show("nada");
}
}
}
public class Server
{
TcpListener ServerListener;
Socket Connexion;
NetworkStream DataStream;
StreamReader Reader;
StreamWriter Writer;
string sData;
public Server()
{
IPAddress IPLocalhost = IPAddress.Parse("127.0.0.1");
//first commandment: create the listener
ServerListener = new TcpListener(IPLocalhost, 65000);
//second commandment: start it!
ServerListener.Start();
}
public void Running()
{
try
{
//third commandment: associate the Listener with the socket to receive data
while(true)
{
Connexion = ServerListener.AcceptSocket();
if(Connexion.Connected)
{
//Put 1252 in (static)GetEncoding method for windows operating system encoding
//System.Text.Encoding FormattedEncoding = System.Text.Encoding.GetEncoding(0);
DataStream = new NetworkStream(Connexion);
Reader = new StreamReader(DataStream);
Writer = new StreamWriter(DataStream);
while(DataStream != null && sData != "Close connection")
{
sData = Reader.ReadLine();
}
}
}
Reader.Close();
Writer.Close();
DataStream.Close();
Connexion.Close();
Application.Exit();
}
catch(SocketException SocketEx)
{
MessageBox.Show(SocketEx.Message);
}
}
public bool IsConnected()
{
return Connexion.Connected;
}
public void Write(string sData)
{
Writer.WriteLine(DataStream);
}
}
}

GeneralRe: My TcpListener doesn't works Pin
User 665828-Jun-05 5:30
User 665828-Jun-05 5:30 
GeneralDate Insertion in mySQL Database Pin
Jassim Rahma28-Jun-05 2:56
Jassim Rahma28-Jun-05 2:56 
GeneralRe: Date Insertion in mySQL Database Pin
Colin Angus Mackay28-Jun-05 3:53
Colin Angus Mackay28-Jun-05 3:53 
GeneralRe: Date Insertion in mySQL Database Pin
metalsandman28-Jun-05 4:03
metalsandman28-Jun-05 4:03 
GeneralRe: Date Insertion in mySQL Database Pin
Colin Angus Mackay28-Jun-05 4:52
Colin Angus Mackay28-Jun-05 4:52 
General,Date Insertion in mySQL Database Pin
Jassim Rahma28-Jun-05 2:52
Jassim Rahma28-Jun-05 2:52 
GeneralRe: ,Date Insertion in mySQL Database Pin
Colin Angus Mackay28-Jun-05 3:46
Colin Angus Mackay28-Jun-05 3:46 
GeneralRe: ,Date Insertion in mySQL Database Pin
Dave Kreskowiak28-Jun-05 4:38
mveDave Kreskowiak28-Jun-05 4:38 
Questionhow to create a file as hidden? Pin
Green Fuze28-Jun-05 0:58
Green Fuze28-Jun-05 0:58 
AnswerRe: how to create a file as hidden? Pin
Hesham Amin28-Jun-05 1:52
Hesham Amin28-Jun-05 1:52 
GeneralRe: how to create a file as hidden? Pin
Green Fuze28-Jun-05 3:58
Green Fuze28-Jun-05 3:58 
GeneralGenerate an Image using ByteCode/HexaView Pin
MDKrishan27-Jun-05 21:29
MDKrishan27-Jun-05 21:29 
GeneralGenerate an Image using ByteCode/HexaView Pin
MDKrishan27-Jun-05 21:25
MDKrishan27-Jun-05 21:25 
GeneralDataAdapter.Fill Problems Pin
metalsandman27-Jun-05 21:20
metalsandman27-Jun-05 21:20 
GeneralRe: DataAdapter.Fill Problems Pin
Piovra_27-Jun-05 21:38
Piovra_27-Jun-05 21:38 
GeneralRe: DataAdapter.Fill Problems Pin
metalsandman27-Jun-05 23:44
metalsandman27-Jun-05 23:44 
GeneralRe: DataAdapter.Fill Problems Pin
Dave Kreskowiak28-Jun-05 4:34
mveDave Kreskowiak28-Jun-05 4:34 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.