~ 1 segundo TcpListener Pending () / AcceptTcpClient () lag
Probablemente solo mire este video:http://screencast.com/t/OWE1OWVkO Como puede ver, el retraso entre el inicio de una conexión (a través de telnet o firefox) y mi programa primero se enteró.
Aquí está el código que espera la conexión
public IDLServer(System.Net.IPAddress addr,int port)
{
Listener = new TcpListener(addr, port);
Listener.Server.NoDelay = true;//I added this just for testing, it has no impact
Listener.Start();
ConnectionThread = new Thread(ConnectionListener);
ConnectionThread.Start();
}
private void ConnectionListener()
{
while (Running)
{
while (Listener.Pending() == false) { System.Threading.Thread.Sleep(1); }//this is the part with the lag
Console.WriteLine("Client available");//from this point on everything runs perfectly fast
TcpClient cl = Listener.AcceptTcpClient();
Thread proct = new Thread(new ParameterizedThreadStart(InstanceHandler));
proct.Start(cl);
}
}
(Estaba teniendo problemas para introducir el código en un bloque de código)
He intentado un par de cosas diferentes, ¿podría ser que estoy usando TcpClient / Listener en lugar de un objeto Socket sin procesar? No es una sobrecarga TCP obligatoria, lo sé, y he intentado ejecutar todo en el mismo hilo, etc.