在RHEL6(这是我的目标生产系统)上运行时,以下代码始终无法连接到套接字,但在Ubuntu上正常工作。
int client_connect(char * socketId) {
int len;
struct sockaddr_un remote;
if (socketId == NULL) {
printf("ERROR: No socket ID given to the simulator\n");
return 1;
}
if ((sock = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) {
printf("ERROR: The simulator failed to create a socket! %s\n", strerror(errno));
return 1;
}
printf("[DEBUG] The socket ID is: %s\n", socketId);
remote.sun_family = AF_UNIX;
strcpy(remote.sun_path, socketId);
len = strlen(remote.sun_path) + sizeof(remote.sun_family);
if (connect(sock, (struct sockaddr *)&remote, len) == -1) {
printf("ERROR: The simulator failed to connect to Origen's socket! %s\n", strerror(errno));
return 1;
}
return 0;
}
输出结果为:
[DEBUG] The socket ID is: /tmp/224414844153787363172.sock
ERROR: The simulator failed to connect to Origen's socket! No such file or directory
套接字肯定存在,传入此函数的ID绝对正确。
我不知道问题可能是什么,特别是因为它适用于其他系统。
欣赏任何想法或建议!