c# - 使用 .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
解决方案
推荐阅读
- excel - 使用Powershell打开受密码保护的Excel xlsx文件并保存为没有密码的csv
- c# - 如何在不更改其内存位置的情况下将类的值复制到其他类
- c++ - 有没有办法使用 gdb 检查分段错误发生在哪里?
- python - 在不识别换行符的情况下打印列表。我不知道如何用语言表达
- node.js - npm install --no-optional 缺少必需的参数
- c# - C++ 中的“笛卡尔积”方法
- c++builder - 如何在 Rad Studio (C++ Builder) 10.3 中更改编译器
- json - Golang 解组数组给出运行时错误:索引超出范围
- r - 根据 r 中的条件,用一组新的观察值替换特定的观察值
- sas - 如何将一个表的值作为 SAS Base 中另一个表的名称?