Server program error: Unable to read data from the transport connection
-
OKay, so I am writing a server program that connects many clients and sends them out data. The problem is that when a client disconnects, when trying to read from another client I get the error.."Unable to read data from the transport connection: An established connection was aborted by the software in your host machine." I have the connections saved in a Dictionary
private Dictionary<TcpClient, string> Connections = new Dictionary<TcpClient, string>();
//to add a client
Connections.Add(tcpClient, currUser);
// to remove a client
Connections.Remove(tcpUser);//server just loops (in a separate thread for each connection)
string message = srReceiver.ReadLine();//client code
// setting up connection
tcpServer = new TcpClient();
tcpServer.Connect(IPAddress.Parse(ipaddress), port);
swSender = new StreamWriter(tcpServer.GetStream());// sending stuff
swSender.WriteLine("Whatever");
swSender.Flush();// closing connection
swSender.WriteLine("Close");
swSender.Flush();
swSender.Close();
tcpServer.Close(); -
OKay, so I am writing a server program that connects many clients and sends them out data. The problem is that when a client disconnects, when trying to read from another client I get the error.."Unable to read data from the transport connection: An established connection was aborted by the software in your host machine." I have the connections saved in a Dictionary
private Dictionary<TcpClient, string> Connections = new Dictionary<TcpClient, string>();
//to add a client
Connections.Add(tcpClient, currUser);
// to remove a client
Connections.Remove(tcpUser);//server just loops (in a separate thread for each connection)
string message = srReceiver.ReadLine();//client code
// setting up connection
tcpServer = new TcpClient();
tcpServer.Connect(IPAddress.Parse(ipaddress), port);
swSender = new StreamWriter(tcpServer.GetStream());// sending stuff
swSender.WriteLine("Whatever");
swSender.Flush();// closing connection
swSender.WriteLine("Close");
swSender.Flush();
swSender.Close();
tcpServer.Close();I wanted to add that the dictionary looks fine after the user has been removed. And this works fine as long as everyone stays connected