C#TCP/IP客户端出现IO异常
IO异常:“无法从传输连接读取数据:已建立的连接被主机中的软件中止。” 代码是从教程中复制的,我确信这个错误与我自己的机器有关。我所有的防火墙,ESET和Windows都关闭了。客户端通过端口555连接 编辑: 客户端C#TCP/IP客户端出现IO异常,c#,exception,client,io,tcp,C#,Exception,Client,Io,Tcp,IO异常:“无法从传输连接读取数据:已建立的连接被主机中的软件中止。” 代码是从教程中复制的,我确信这个错误与我自己的机器有关。我所有的防火墙,ESET和Windows都关闭了。客户端通过端口555连接 编辑: 客户端 static void Main(string[] args) { MakeClientCallToServer("test"); MakeClientCallToServer("test2"); MakeClien
static void Main(string[] args)
{
MakeClientCallToServer("test");
MakeClientCallToServer("test2");
MakeClientCallToServer("test3");
// Now send a bunch of messages...
string msg;
for (int i = 0; i < 100; i++)
{
msg = string.Format(Thread.CurrentThread.CurrentCulture,
"I'll not be ignored! (round {0})", i);
ThreadPool.QueueUserWorkItem(new
WaitCallback(MakeClientCallToServer), msg);
}
Console.WriteLine("\n Press any key to continue... ");
Console.Read();
}
static void MakeClientCallToServer(object objMsg)
{
string msg = (string)objMsg;
MyTcpClient client = new MyTcpClient(IPAddress.Loopback, 55555);
client.ConnectToServer(msg);
}
我已经创建了名为MyTcpServer和MyTcpClient的类来处理所有常见的连接、线程等。您可以尝试使用Wireshark捕获数据流以查看发生了什么。我们是否可以看到一些代码
你是对的,这个错误最常见的原因是机器上有阻塞,所以关闭所有这些东西是一个伟大的第一步。但是,由于这种情况仍在发生,您能否加载以查看您的数据包发生了什么情况?Wireshark不会嗅探任何信息。如果您在Vista上运行它,您是否以管理员身份运行它?你在正确的设备上嗅探吗?
static MyTcpServer server;
static void Main(string[] args)
{
ThreadPool.QueueUserWorkItem(RunServer);
Console.WriteLine("Press esc to stop the server...");
ConsoleKeyInfo cki;
while (true)
{
cki = Console.ReadKey();
if (cki.Key == ConsoleKey.Escape)
{
break;
}
}
}
static void RunServer(object stateInfo)
{
//Initiate the server)
server = new MyTcpServer(IPAddress.Loopback, 55555);
server.Listen();
}