There are several points in my application where the server needs to disconnect a client. For some reason, calling TcpClient.Close() in an event handler prevents the DataReceived event from being invoked when other clients send data.
Below is a sample that demonstrates this issue:
var server = new SimpleTcpServer();
server.DataReceived += (s, a) =>
{
Console.WriteLine("Data");
a.TcpClient.Close();
};
server.ClientConnected += (s, a) =>
{
Console.WriteLine("Connected");
};
server.Start(8088);
Console.ReadLine();
server.Stop();
Using the code above and an application like PacketSender to test, I expect that a connection would be closed each time data is sent to the server. Instead, the first client to connect to the server is disconnected after data is sent and subsequent connections never raise the DataReceived event.
There are several points in my application where the server needs to disconnect a client. For some reason, calling TcpClient.Close() in an event handler prevents the DataReceived event from being invoked when other clients send data.
Below is a sample that demonstrates this issue:
Using the code above and an application like PacketSender to test, I expect that a connection would be closed each time data is sent to the server. Instead, the first client to connect to the server is disconnected after data is sent and subsequent connections never raise the DataReceived event.