WinSock error with recv() function.
-
Vis C/C++ 6.0, Visual Studio My program is a client to read a web page. I am successfully setting up the socket. The following calls and assignments are successful WSAStartup() memset(&sa,0,sizeof(sa)); sa.sin_family = AF_INET; gethostbyname(gipaddrname); // example yahoo.com memcpy(&sa.sin_addr, phe->h_addr, phe->h_length); sa.sin_port = portn; //port 80 converted to net order getprotobyname("tcp"); socktype = SOCK_STREAM; sockdes = socket(PF_INET, socktype, ppe->p_proto); connect(sockdes, (struct sockaddr *)&sa, sizeof(sa)); But when I go to receive the Servers 'hello' message with: recv(sockdes, pbufbin, len, 0); I get the error: WSAECONNABORTED The virtual circuit was terminated due to a time-out or other failure. The application should close the socket as it is no longer usable. The strange thing is that I have used this exact code for other servers, such a pop3 mail servers and servers that I wrote, all without a problem.... Any help would be much appreciated :-) Many thanks, Robert
-
Vis C/C++ 6.0, Visual Studio My program is a client to read a web page. I am successfully setting up the socket. The following calls and assignments are successful WSAStartup() memset(&sa,0,sizeof(sa)); sa.sin_family = AF_INET; gethostbyname(gipaddrname); // example yahoo.com memcpy(&sa.sin_addr, phe->h_addr, phe->h_length); sa.sin_port = portn; //port 80 converted to net order getprotobyname("tcp"); socktype = SOCK_STREAM; sockdes = socket(PF_INET, socktype, ppe->p_proto); connect(sockdes, (struct sockaddr *)&sa, sizeof(sa)); But when I go to receive the Servers 'hello' message with: recv(sockdes, pbufbin, len, 0); I get the error: WSAECONNABORTED The virtual circuit was terminated due to a time-out or other failure. The application should close the socket as it is no longer usable. The strange thing is that I have used this exact code for other servers, such a pop3 mail servers and servers that I wrote, all without a problem.... Any help would be much appreciated :-) Many thanks, Robert
Robert Palma Jr. wrote:
memcpy(&sa.sin_addr, phe->h_addr, phe->h_length);
try changing this line to
(&sa.sin_addr.s_addr,phe->h_addr,phe->h_length);
Hope this helps you.KIRAN PINJARLA
-
Robert Palma Jr. wrote:
memcpy(&sa.sin_addr, phe->h_addr, phe->h_length);
try changing this line to
(&sa.sin_addr.s_addr,phe->h_addr,phe->h_length);
Hope this helps you.KIRAN PINJARLA
Hi Kiran, Thank-you for input. I made the change but still get the same result. Hmmm .... Any other thoughts? Many thanks, Robert:)