我正在尝试在Linux上在同一网络上连接的两台PC之间建立基本的客户端-服务器连接。
我已成功将客户端连接到本地计算机上的服务器。 但是,当我通过“ ifconfig”命令为客户机提供服务器PC的IP时,我有:连接被拒绝。 由于命令,我已经打开了我使用的端口:sudo firewall-cmd --add-port = 4242 / tcp
这是我如何使用从“ ifconfig”命令获得的IP地址“ xxx.xxx.xxx.xxx”设置套接字连接的方法(也许这不是正确的方法吗?)。
// Establish the remote endpoint
// for the socket.
IPHostEntry ipHost = Dns.GetHostEntry(Dns.GetHostName());
IPAddress ipAddr = IPAddress.Parse("xxx.xxx.xxx.xxx");
IPEndPoint localEndPoint = new IPEndPoint(ipAddr, 4242);
// Creation TCP/IP Socket using
Socket sender = new Socket(ipAddr.AddressFamily,
SocketType.Stream, ProtocolType.Tcp);
以下是异常输出: SocketException:System.Net.Internals.SocketExceptionFactory + ExtendedSocketException(111):连接被拒绝xxx.xxx.xxx.xxx:4242