我已经在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 !