Connection time out on sockets

Viewed 65

Good day everyone! I'm still doing research on this so please pardon if I make any mistake. I'm currently working on a small project that need socket connection between 2 device, problem is, when ever I used the client and the server on the same device, it worked out okay. But when I moved the client into a different device, then started the process again(same LAN connection), it just gave me the time out error [WinError 10060]. Here is my code:

Server side:

HOST = '10.0.0.32'
PORT = 44132
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server.bind((HOST, PORT))
server.listen()
client, address = server.accept()

Client side:

HOST = '10.0.0.32'
PORT = 44132
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client.connect((HOST, PORT))

I have tried disabling the Firewall and restart computer, changing port or trying to check in cmd if server is really Listening or not, is there anything that I'm missing here? Thank you.

The full error report is: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond

edit: Here is also my port listening on 44132 using netstat:

Proto Local Address Foreign Address State

TCP 0.0.0.0:44132 0.0.0.0:* LISTENING

edit2: Another update on my end, I've tried turning off the firewall on target machine and ping it, the ping now went through successfully but the client and server still refused to reconnect and continue on timing out. Could it be that there is another firewall between my 2 devices and are implemented by the router to prevent the connection taking place?

1 Answers

Probably you are using the wrong ip address, my advice is to use the command arp -a to check if the server's ip is correct (if you have access to the router you could check there otherwise).

Moreover, be aware when you use socket.gethostbyname(socket.gethostname()), take a look here Python socket.gethostname

Related