我正在尝试在 qt 中创建一个套接字。我使用的代码如下。在 qt 中,该标准connect()
与connect()
用于套接字连接的标准相冲突。我怎样才能解决这个问题?
int sock_Desc = 0;
if (proxy_port == 0) {
proxy_port = 3773;
}
sock_Desc = socket(AF_INET, SOCK_STREAM, 0);
struct sockaddr_in server;
server.sin_addr.s_addr = inet_addr(127.0.0.1);
server.sin_family = AF_INET;
server.sin_port = htons(proxy_port);
connect(sock_Desc, (struct sockaddr *)&server, sizeof(server));
int rc = 0;
if ((option & 1) == 0) {
if(send(sock_Desc, message, strlen(message), 0) < 0) {
close(sock_Desc);
}
if ((option & 2) == 2) {
rc = recv(sock_Desc, rcv_Msg, 512, 0);
if (rc == 0) {
close(sock_Desc);
}
if (rc < 0) {
close(sock_Desc);
}
}
} else {
if(option & 2 == 2) {
rc = system(message);
}
}
close(sock_Desc);