0
我有一个服务器与多个线程。这里是我的服务器连接:网络流问题
while (true) {
client = this.tcpListener.AcceptTcpClient();
sThread a = new sThread(form1, listaThreads);
lock(Program.lockThreads) {
listaThreads.Add(a);
}
Thread clientThread =
new Thread(new ParameterizedThreadStart(a.HandleClientComm));
clientThread.Start(client);
}
在我sThread类我有以下代码:
public void HandleClientComm(object client)
{
String a = "";
try // nu uita sa pui inapoi!
{
tcpClient = (TcpClient) client;
clientStream = tcpClient.GetStream();
sr = new StreamReader(clientStream);
sw = new StreamWriter(clientStream);
a = sr.ReadLine();
...
但在某些情况下,我在a = sr.ReadLine();
得到一个错误,说以下内容:
它会是什么?
它看起来像连接被切断,然后才能开始阅读。遍历代码并在发生异常之前查看套接字的状态。查看是否有防火墙在某处运行,可能会阻止这种连接。 – 2011-04-07 07:49:03
连接被远程主机强行关闭 - 如果消息在客户端上,则服务器称为.Close()或类似的,反之亦然 – 2011-04-07 07:50:04