So I got the connection timed out error (error 110)

This is the IP address I got from ipconfig /all: IP address in red circle

And this is the code I use for client (the RasPi): import socket

TCP_IP = '192.168.2.52'
TCP_PORT = 5005
BUFFER_SIZE = 1024 

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((host,port))  #this is where the error came in
s.send(message)
data = s.recv(BUFFER_SIZE)
s.close()

print("Received data: ", data)

This is the code I have for the host computer:

import socket

TCP_IP = ''
TCP_PORT = 5005
BUFFER_SIZE = 1024 

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((TCP_IP, TCP_PORT))
s.listen(1)

conn, addr = s.accept()
print ('Connection address:', addr)
while 1:
    data = conn.recv(BUFFER_SIZE)
    if not data: break
    print ("received data:", data)
    conn.send(data)  # echo
conn.close()

Both of the devices are connected to the same network, but I have been tinkering around for the last couple of hours but still failed to get a connection between the 2.

Any idea? Seems like a pretty basic snippet of code. Thanks!

  • In your first code snippet: 's.connect((host,port))' host and port are undefined (at least not in the snippet given). – Charemer Nov 22 at 10:08
  • @Charemer Yeah sorry, I should have fixed that, but that's a typo when I try to retype the code from the raspi, apart from that, do you see anything wrong? – Việt England Nov 22 at 10:30
  • 1
    @ViệtEngland There is little point commenting until you edit the question to include the code you are using. – joan Nov 22 at 10:48
  • 1
    are you able to ping from node to node? – oh.dae.su Nov 22 at 13:03

Since your server seems to be windows-based, you're likely being bitten by the firewall. Disable it, or make an exception for port 5005.

Alternatively, try running the server snipped on the RPi and the client snippet on the computer, and see how that goes.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.