Reputation: 51
I'm trying to create a socket in qt. The code I use is the following. In qt, the standard connect()
is in conflict with connect()
used for socket connection. How can I fix this?
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);
Upvotes: 1
Views: 1655
Reputation: 45665
The function connect
from the socket header (sys/socket.h
on linux) is in the global namespace since it's a C header file. You can explicitly refer to the global namespace by writing
::connect(sock_Desc, (struct sockaddr *)&server, sizeof(server));
Upvotes: 4