TCPListener will not accept incoming connection
I am having an issue recieving data from my asyncronous server on my non-asyncronous client (for reasons of variable interaction). Can someone tell me why I can't recieve a packet back from my server with the following code:
Code:
public static void StartListening()
{
TcpListener listener = new TcpListener(IPAddress.Parse("127.0.0.1"), 7345);
listener.Start(1);
while (true)
{
Socket socket = listener.AcceptSocket();
NetworkStream stream = new NetworkStream(socket);
byte[] readData = new byte[1024];
int readBytes = 0;
readBytes = stream.Read(readData, 0, 1024);
string Message = Encoding.ASCII.GetString(readData).Substring(0, readBytes);
HandleMessage(Message);
stream.Close();
break;
}
listener.Stop();
}
It is really starting to bother me and I need some help, thanks!
Re: TCPListener will not accept incoming connection
i think you should create a thread that will start receiving packets after you a client has connected to your server...