首页 > 解决方案 > 使用 .net 进行 PC 间连接

问题描述

我正在尝试在 Linux 上连接在同一网络上的两台 PC 之间建立基本的客户端-服务器连接。

我成功地将客户端连接到本地计算机上的服务器。但是当我通过'ifconfig'命令给我的客户服务器PC的IP时,我有:连接被拒绝。由于以下命令,我已经打开了我使用的端口:sudo firewall-cmd --add-port=4242/tcp

这是我使用“xxx.xxx.xxx.xxx”设置套接字连接的方法,该地址是我从“ifconfig”命令获得的 IP 地址(也许这不是正确的方法?)。

// 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): Connection denied xxx.xxx.xxx.xxx:4242

标签: c#.netnetwork-programming

解决方案


推荐阅读