Problem:
We are experiencing an excessive (i.e. 16 - 20 seconds) delay when
attempting to establish socket connection over the network, using the
TcpLister.AcceptSocket() and TcpClient.Connect(ipAddress, Port) calls. It
seems that the delay is between client.Connect() and listener.Accept().
We never have a delay when we use a telnet client to connect to the server.
And we do not have a delay on all networks, just on some. The code we are
using to establish the connection follows.
Thanks in advance!
Server Side...
private void AcceptSocketsThread ()
{
IPEndPoint endpoint = new IPEndPoint(IPAddress.Any, m_Port);
listener = new TcpListener(endpoint);
listener.Start();
//infinite loop... if we have a connection request pending, accept it and
save the socket to our local collection.
while(true)
{
if(listener.Pending()==true)
{
connection =listener.AcceptSocket(); // block for a valid client conection
SocketConnectionList.Add(connection); //save the socket
}
else Thread.Sleep(200);
}
}
Client Side...
public bool SetupClientSocket(string ip,string port)
{
TcpClient client = new TcpClient();
IpAddress=ip;
Port=Int32.Parse(port);
try
{
//try connecting to the socket server...
//this is where we're experiencing the delay...
client.Connect(IpAddress,Port);
return(true);
}
catch (Exception error)
{
return(false);
}
}