winsock error 10054 WSAECONNRESET when using loopback ip - why?

Started by
1 comment, last by XXX_Andrew_XXX 19 years, 6 months ago
I'm working on a client/server based network game. It uses UDP. Each instance of the game as two sockaddr_in varaibles, one for itself (m_LocalInfo) and one for the server (m_ServerInfo). It was my intention to treat a single player game as no differently than any other client who wasn't playing on the actual server machine. I was going to set the m_ServerInfo to point to the loopback IP address (127.0.0.1) and just receive messages in the same receive queue that all the messages normally come in on. My problem is that even though I can send messages fine to the loopback IP address, when I try to receive those messages I get a winsock error 10054 on them. If I set the m_ServerInfo to the machines actual IP address, I can send and receive messages just fine. Has anyone else tried this kind of setup? I wanted to avoid writing any more client/server specific code than necessary and sending messages back to itself using the loopback IP seemed like a good way to avoid unneeded network traffic. Any thoughts on this would be appreciated. Thanks!
Advertisement
Hi,

when specifying the address part of sockaddr_in, have you tried using:

TCHAR *lpszIPAddr = 0 ;
hostent *pConnectedHost = 0 ;
struct in_addr *pInAddr = 0 ;

// Please check for NULL return
pConnectedHost = gethostbyname("127.0.0.1") ;
pInAddr = (struct in_addr *)*pConnectedHost->h_addr_list ;
lpszIPAddr = inet_ntoa(*pInAddr) ;
m_ServerInfo.sin_addr.S_un.S_addr = inet_addr(lpszIPAddr) ;

regards
Just an idea...

Under win2k without SP2 this can occur for UDP sockets, it is documented at http://support.microsoft.com/kb/263823 . Not so long ago this was discussed on these forums, you might find more help there.

This topic is closed to new replies.

Advertisement