本文介绍了插座不要真的关闭。请帮助微软MVP!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 这让我发疯了! 请,如果有人可以帮助我。 我正在测试一个版本简单的套接字客户端。 在我的测试中,我只是打开并关闭一个连接(在一个循环中)到我的本地IIS 服务器(端口80) 使用System.Net.Sockets; for(int I = 0; I< 5000; I ++) { TcpClient myClient = new TcpClient(); try { myClient.Connect(" 127.0.0.1" ;,80) } catch(Exception ex){MessangeBox.Show(ex.ToString()); } myClient.Close() } //结束 一切顺利,数千个连接被打开并关闭,直到 出现此错误.... [System.Net.Sockets.SocketException:每个套接字地址只有一种用法 (协议/网络地址/端口)通常是允许的] 出现此错误后,我执行netstat -a命令和行(下方) 出现数千个时间,下面的行只是 完整列表中的一小部分。 TCP asusis-dsgn:3505 localhost:80 TIME_WAIT TCP asusis-dsgn:3506 localhost:80 TIME_WAIT TCP asusis-dsgn:3507 localhost:89 TIME_WAIT TCP asusis-dsgn:3508 localhost:89 TIME_WAIT TCP asusis-dsgn:3509 localhost:89 TIME_WAIT TCP asusis-dsgn:3510 localhost:89 TIME_WAIT TCP asusis-dsgn:3511 localhost:89 TIME_WAIT TCP asusis-dsgn:3512 localhost:89 TIME_WAIT TCP asusis-dsgn:3513 localhost:89 TIME_WAIT TCP asusis-dsgn:3514 localhost:89 TIME_WAIT TCP asusis-dsgn:3515 localhost:89 TIME_WAIT TCP asusis-dsgn:3516 localhost:89 TIME_WAIT TCP asusis-dsgn:3517 localhost:89 TIME_WAIT TCP asusis-dsgn:3518 localhost:89 TIME_WAIT TCP asusis-dsgn:3519 localhost :89 TIME_WAIT TCP asusis-dsgn:3520 localhost:89 TIME_WAIT TCP asusis-dsgn:3521 localhost:89 TIME_WAIT TCP asusis- dsgn:3522 localhost:89 TIME_WAIT TCP asusis-dsgn:3523 localhost:89 TIME_WAIT TCP asusis-dsgn:3524 localhost:89 TIME_WAIT TCP asusis-dsgn:3525 localhost:89 TIME_WAIT TCP asusis-dsgn:3526 localhost:89 TIME_WAIT TCP asusis-dsgn: 3527 localhost:89 TIME_WAIT 我认为由于某种原因,.net框架并没有真正关闭 套接字,因此它仍处于TIME_WAIT状态 经过数千次TIME_WAIT连接,操作系统拒绝连接。 Pleaseeeeee帮助解决它!! 谢谢 This is making me crazy!! Please, if some body can help me. I''m testing a ver simple socket client.In my test I just open and close a connection (in a loop) to my local IISserver (port 80) using System.Net.Sockets; for (int I = 0; I < 5000; I++){TcpClient myClient = new TcpClient();try{myClient.Connect("127.0.0.1", 80)}catch (Exception ex) {MessangeBox.Show(ex.ToString()); }myClient.Close()} //End forEverything go fine, thousands of connections are opened and closed untilthis error appear.... [ System.Net.Sockets.SocketException: Only one usage of each socket address(protocol/network address/port) is normally permitted ] After this error, I execute the netstat -a command and the lines (below)appear thousands of times, lines below are just a very little part of thecomplete list. TCP asusis-dsgn:3505 localhost:80 TIME_WAITTCP asusis-dsgn:3506 localhost:80 TIME_WAITTCP asusis-dsgn:3507 localhost:89 TIME_WAITTCP asusis-dsgn:3508 localhost:89 TIME_WAITTCP asusis-dsgn:3509 localhost:89 TIME_WAITTCP asusis-dsgn:3510 localhost:89 TIME_WAITTCP asusis-dsgn:3511 localhost:89 TIME_WAITTCP asusis-dsgn:3512 localhost:89 TIME_WAITTCP asusis-dsgn:3513 localhost:89 TIME_WAITTCP asusis-dsgn:3514 localhost:89 TIME_WAITTCP asusis-dsgn:3515 localhost:89 TIME_WAITTCP asusis-dsgn:3516 localhost:89 TIME_WAITTCP asusis-dsgn:3517 localhost:89 TIME_WAITTCP asusis-dsgn:3518 localhost:89 TIME_WAITTCP asusis-dsgn:3519 localhost:89 TIME_WAITTCP asusis-dsgn:3520 localhost:89 TIME_WAITTCP asusis-dsgn:3521 localhost:89 TIME_WAITTCP asusis-dsgn:3522 localhost:89 TIME_WAITTCP asusis-dsgn:3523 localhost:89 TIME_WAITTCP asusis-dsgn:3524 localhost:89 TIME_WAITTCP asusis-dsgn:3525 localhost:89 TIME_WAITTCP asusis-dsgn:3526 localhost:89 TIME_WAITTCP asusis-dsgn:3527 localhost:89 TIME_WAIT I think that for some reason the .net framework is not really closing thesocket, so it still alive with the TIME_WAIT status And after thousands of TIME_WAIT connections, the OS reject connections. Pleaseeeeee help to solve it!!Thanks推荐答案 地址 地址 这篇关于插座不要真的关闭。请帮助微软MVP!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-27 14:28