I am trying to connect to a device using the Connect api. And it is giving me WSAECONNREFUSED error. This happens when I have two devices connected and I try to connect to one of the devices. If I connect only one device then the connectino goes through fine.
Could any one of you let me know the problem here.
Here is my code:
sockaddr_in my_addr;
my_addr.sin_family = (USHORT)AF_INET ;
my_addr.sin_port = htons((USHORT)host_port);
memset(&(my_addr.sin_zero), 0, (size_t)8);
my_addr.sin_addr.s_addr = inet_addr(pHostName);
if (connect( (SOCKET)*uiSocket, (struct sockaddr*)&my_addr,
sizeof(my_addr)) == SOCKET_ERROR )
{
int err = WSAGetLastError();
fprintf(stderr, "Error connecting socket %d\n", WSAGetLastError());
closeCxn();
return false;
}
Thanks.
Usually ECONNREFUSED means that the computer you are trying to connect to refused to accept the connection. The usual reason for that is that there is no program listening to the specified port on the target computer.
You can confirm that this is the case by running telnet from a DOS prompt to the same host and port, e.g.:
telnet 192.168.1.99 1234
(Replace the example arguments above with the appropriate IP address and port number, of course). If telnet exits immediately with a "Connection refused" method, then you know the problem is on the remote computer. If it connects and stays connected, then the problem is more likely with your local computer's program.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With