When I use the function connect()on the i7 computer, it always returns zero, regardless of whether it was able to connect or not. I just do not have another application to connect, and it still returns zero (server address 127.0.0.1).
When I run the same application on another computer, it behaves correctly. So what could be the problem?
Thank.
Change the transition from the answer below.
The code
struct hostent* pHostEntry;
pHostEntry = gethostbyname(host);
if(pHostEntry == NULL)
{
return 0;
}
struct in_addr* host_addr = (struct in_addr*) * pHostEntry->h_addr_list;
if(host_addr == NULL)
{
return 0;
}
long sockfd;
if((sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0)
{
return 0;
}
memset((char*) &serv_addr, 0, sizeof(serv_addr));
serv_addr.sin_family = AF_INET;
serv_addr.sin_addr = *host_addr;
serv_addr.sin_port = htons(port);
if(connect(sockfd, (struct sockaddr*)&serv_addr, sizeof(serv_addr)) == SOCKET_ERROR)
{
CloseSocket();
sockfd = -1;
return 0;
}
. . , , , - . . , , , . , . i7 → Intel (R (Core (TM) i7 CPU 930 @2,80 2.80 . . ( Windows 7) . , - . .