设备无法通过套接字与特定设备通信

时间:2018-03-12 07:05:10

标签: c++ sockets networking network-programming

我有三台设备连接到路由器(jetson,raspberry pi和mac)。这三个设备可以相互ping通,并且ssh就好了。但是,当我尝试通过套接字与本教程https://www.geeksforgeeks.org/socket-programming-cc/中概述的代码进行通信时,mac无法连接到jetson。 jetson可以很好地与其他设备进行通信。

通过SFML使用套接字时出现同样的问题。

如果有帮助,这是套接字代码:

服务器:

cout << "Launching remote joystick communications link..." << endl;
server_fd = socket(AF_INET, SOCK_STREAM, 0);
setsockopt(server_fd, SOL_SOCKET, SO_REUSEADDR | SO_REUSEPORT, &opt, sizeof(opt));

address.sin_family = AF_INET;
address.sin_addr.s_addr = INADDR_ANY;
address.sin_port = 2223;

bind(server_fd, (struct sockaddr *) &address, sizeof(address));
listen(server_fd, 3);

cout << "Waiting for joystick client..."  << endl;
new_socket = accept(server_fd, (struct sockaddr *)&address, (socklen_t*)&addrlen);

客户端:

struct sockaddr_in address;
int sock = 0, valread;
struct sockaddr_in serv_addr;

sock = socket(AF_INET, SOCK_STREAM, 0);
memset(&serv_addr, '0', sizeof(serv_addr));

serv_addr.sin_family = AF_INET;
serv_addr.sin_port = htons(2223);

inet_pton(AF_INET, IP_ADDR, &serv_addr.sin_addr);

0 个答案:

没有答案