Winsock returns 10061 on connect only to localhost

后端 未结 1 1530
说谎
说谎 2021-01-22 14:47

I dont understand whats happening. If I create a socket to anywhere else other than localhost (either \"localhost\", \"127.0.0.1\" or the external ip of the machine) it works fi

相关标签:
1条回答
  • 2021-01-22 15:37

    You are not guaranteed to get a WSAETIMEDOUT error when connecting to a non-listening port on another machine. Any number of different errors can occur. However, a WSAETIMEDOUT error typically only occurs if the socket cannot reach the target machine on the network before connect() times out. If it can reach the target machine, a WSAECONNREFUSED error means the target machine is acknowledging the connect() request and is replying back saying the requested port is not able to accept the connection at that time because either it is not listening or its backlog is full (there is no way to differentiate which). So, when you are connecting to the localhost, you will pretty much always get a WSAECONNREFUSED error when connecting to a non-listening port because you are connecting to the same machine and there is no delay in determining the port's listening status. It has nothing to do with firewalls or anti-malwares. This is just normal behavior.

    0 讨论(0)
提交回复
热议问题