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