尝试连接到 TCP 套接字 (Linux) 时连接被拒绝
Connection Refused when trying to connect to tcp socket (linux)
我正在使用 VM ware 开发 ubunto Linux 版本 14.04 (linux(
我已经在 ubunto 14.04 (linux( 下用 c++ 创建了 TCP 套接字 但是当我尝试使用套接字的"连接"方法时,它失败并说 连接拒绝。我试图关闭我的Windows(10(计算机中的防火墙,但它根本没有帮助。
您的帮助将不胜感激!
TCPSocket::TCPSocket(string peerIp, int port) {
// Open TCP socket
this->connected_sock = socket(AF_INET, SOCK_STREAM, 0);
if (this->connected_sock < 0) {
perror("Error opening channel");
}
// Set the peer address to connect to
bzero(&this->peerAddr, sizeof(this->peerAddr));
this->peerAddr.sin_family = AF_INET;
this->peerAddr.sin_addr.s_addr = inet_addr(peerIp.c_str());
this->peerAddr.sin_port = htons(port);
// FAILED HERE
if (connect(this->connected_sock, (struct sockaddr *) &this->peerAddr,
sizeof(this->peerAddr)) < 0) {
perror("Error establishing communications");
throw "Error establishing communications";
}
}
你的代码没有错。connection refused
意味着路径上的某个地方有人将TCP重置数据包发送回原始源。在显著的点使用网络流量监控工具(例如tcpdump,wireshark(来跟踪故障的位置。tcpdump 示例:tcpdump -i <interface_name> -nnvvvXX host <destination_ip> and tcp port <destination_port>
所以我解决了这个问题!
我哑巴...
灵魂在调用=>我调用了不同的端口。
服务器侦听端口 13301 并且客户端需要连接到同一端口, 只有这样,服务器才会接受客户端并与他一起打开新的套接字。
非常感谢您的帮助!
相关文章:
- 如何在 Linux 中务实地检索连接的接入点信息
- 从 Linux OMI (omicli) 到 Windows WMI 的连接失败,并出现与 DMTF 相关的错误
- Linux C++编程:为什么连接是.so,生成的可执行依赖库是.so.version
- 尝试连接到 TCP 套接字 (Linux) 时连接被拒绝
- 图形工具:在Linux中编译并连接到本地CGAL库?(没有须藤)
- Linux 套接字 recv 返回 -1,errno 110 连接超时
- 获取使用 Qt c++ 在 Linux 中通过 USB 连接的 ESC/POS 打印机的状态
- C 在Linux Ubuntu上检查Internet连接
- C++ Linux 上的套接字连接
- SQL Server 2017 C++ ODBC 连接在 Linux 上不起作用
- NAS(使用 qt/linux)- 无法建立简单的音频服务器连接测试
- Linux复制文件连接到节点JS / Python / C / C 之后
- 如何在非网关接口 Linux 上检测互联网连接
- 信号插槽在windows下连接,在linux下连接NOT
- curl停止在Linux上使用多个连接进行下载
- poll()套接字编程tcp-linux多连接问题
- 在linux上的c++中获取活动的TCP/UDP连接
- 使用termios api(c++)检测Linux中的角色设备是否已断开连接
- 哪个c/c++库可以用来处理linux的wifi连接
- 如何在 Linux 中创建可通过屏幕应用程序连接的 pty