如何解决c#服务器套接字创建IPEndPoint 127.0.0.1,“连接被拒绝”,错误代码:10061
我已经在Windows 10 Pro下的C#中创建了一个TCP套接字,但是当我尝试使用Connect()
方法时,它失败了,并说连接被拒绝。
我试图关闭Windows防火墙,但是它根本没有帮助。
_socket = new Socket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp);
_socket.setSocketOption(SocketOptionLevel.Tcp,SocketOptionName.NoDelay,true);
_socket.SendTimeout = 2000;
_socket.ReceiveTimeout = 2000;
IPHostEntry ipHost = Dns.Resolve("localhost");
IPAddress ipAddr = ipHost.AddressList[0];
//IPEndPoint ipEnd = new IPEndPoint(IPAddress,TCPPort);
//_socket.Connect(ipEnd);
_socket.Connect(new IPEndPoint(IPAddress,TCPPort));
- ex {"The connection could not be made because the target computer refused it 127.0.0.1:11111"} System.Exception {System.Net.Sockets.SocketException} + Data {System.Collections.ListDictionaryInternal} System.Collections.IDictionary {System.Collections.ListDictionaryInternal} ErrorCode 10061 int HResult -2147467259 int HelpLink null string + InnerException null System.Exception Message "The connection could not be made because the target computer refused it 127.0.0.1:11111" string NativeErrorCode 10061 int SocketErrorCode ConnectionRefused System.Net.Sockets.SocketError Source "System" string StackTrace " at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot,SocketAddress socketAddress)\r\n at System.Net.Sockets.Socket.Connect(EndPoint remoteEP)\r\n at ModbusMaster.MasterForm.BtnConnectClick(Object sender,EventArgs e) in D:\\개인\\프로젝트\\02.ABH\\개발\\03.구현\\source\\ModbusTool-master\\ModbusTool-master\\ModbusMaster\\MasterForm.cs:line 94" string + TargetSite {Void DoConnect(System.Net.EndPoint,System.Net.SocketAddress)} System.Reflection.MethodBase {System.Reflection.RuntimeMethodInfo} + Static members + Non-Public members !
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。