C# Programming
01-27-2010, 01:30 PM
Hi,
I would like to code a TCP/UDP server and I've coded a major part of it but it seems like if the server is busy, then I will have a problem.
Here is my Listening code:
private void Listen()
{
Console.WriteLine( "Listening port " + port.ToString() +"." );
listener.Start();
while (KeepWorking)
{
// Waiting until a client requests to connect.
TcpClient client = listener.AcceptTcpClient();
Console.WriteLine("---------------------");
Console.WriteLine(client.Client.RemoteEndPoint.ToString() + " connected.");
ClientHistory.Add( client.Client.RemoteEndPoint.ToString() );
ThreadPool.QueueUserWorkItem(new WaitCallback(HandleCommunication), client);
}
}
If more than one client requests to connect at the same time then one won't be able to connect because I am not listening.
If a client connects and before it's queued to ThreadPool another client wants to connect, it won't be able to connect because I am not listening again.
Is there a way to solve this or is this how every server works? http://www.barakasoft.com/script/Forums/Images/smiley_smile.gif
Thanks.
modified on Tuesday, January 26, 2010 5:24 AM
I would like to code a TCP/UDP server and I've coded a major part of it but it seems like if the server is busy, then I will have a problem.
Here is my Listening code:
private void Listen()
{
Console.WriteLine( "Listening port " + port.ToString() +"." );
listener.Start();
while (KeepWorking)
{
// Waiting until a client requests to connect.
TcpClient client = listener.AcceptTcpClient();
Console.WriteLine("---------------------");
Console.WriteLine(client.Client.RemoteEndPoint.ToString() + " connected.");
ClientHistory.Add( client.Client.RemoteEndPoint.ToString() );
ThreadPool.QueueUserWorkItem(new WaitCallback(HandleCommunication), client);
}
}
If more than one client requests to connect at the same time then one won't be able to connect because I am not listening.
If a client connects and before it's queued to ThreadPool another client wants to connect, it won't be able to connect because I am not listening again.
Is there a way to solve this or is this how every server works? http://www.barakasoft.com/script/Forums/Images/smiley_smile.gif
Thanks.
modified on Tuesday, January 26, 2010 5:24 AM