3

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?

Vuong Duong
  • 53
  • 1
  • 7
  • Is the server code actually running on 10.0.0.32? – Tim Roberts Aug 14 '22 at 05:01
  • Hi @TimRoberts, yes it is. I used `socket.gethostbyname(socket.gethostname())` at first but reckon putting the private ip in there would be easier for you guys to see so I changed it – Vuong Duong Aug 14 '22 at 05:05
  • And are both machines on the same subnet? So, can you "ping 10.0.0.32" from the client machine? – Tim Roberts Aug 14 '22 at 06:53
  • I'm just started with networking so I'm not sure what a subnet is, but I've tried to ping the other machine ipv4 and it return time error too, I tried searching around internet for that but they just seem to tell me to disable firewall – Vuong Duong Aug 14 '22 at 07:12
  • if this could help then I'd also want to add that those 2 are on the same wifi network, I did tried to do `ping 10.0.0.32` but all it returned was `request timed out` – Vuong Duong Aug 14 '22 at 07:18
  • Don't bind the server to `'10.0.0.32'`. Bind it to `0.0.0.0`. – user207421 Aug 14 '22 at 10:14
  • Hi @user207421, I've already tried that before but it gave the same error code. I'm using this on 1 LAN only so I don't think I need port map either....Thank you for your advice! – Vuong Duong Aug 14 '22 at 18:46

1 Answers1

0

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

  • I'm sorry for the late reply, I've checked my ipconfig and there are no virtual machine or another adapter ip address, that's why I used `socket.gethostbyname(socket.gethostname())`. the Ipv4 address showed on my ipconfig said 10.0.0.32 and when I used the command it also returned that number. Arp -a also give the same ipv4 in Internet address so I'm not sure what's wrong here. Thank you! – Vuong Duong Aug 14 '22 at 18:43