T.Justice
T.Justice

Reputation: 75

TimeoutError python socket

I would like to make a BT communication between a laptop with a dongle BT and a Raspberry. They are both connected on a PAN network so they have both one IP address.

For the communication, I use a TCP socket. On the server part, I can create my socket until the accept method. Then I go on my RPi 3 and I run my python script:

import socket

hote = "192.168.50.1"
port = 1000

socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
socket.connect((hote, port))
print("Connection on {}".format(port))
socket.close()

But I always have this output after few minutes:

  Traceback (most recent call last):
  File "socketClient.py", line 7, in <module>
    socket.connect((hote, port))
TimeoutError: [Errno 110] Connection timed out

I don't know why... Do you have an idea ? I've tried the command telnet addr_ip port on my laptop and i success the connection with the server.

Upvotes: 1

Views: 3438

Answers (2)

T.Justice
T.Justice

Reputation: 75

It was a firewall problem because he stopped the entrance connection.I realized there when I reversed the roles. I put the server code on RPI and client code on my laptop and it worked.

Upvotes: 3

Dawid Dave Kosiński
Dawid Dave Kosiński

Reputation: 901

First of all, did you bind the socket? Second, are you listening on that IP and port?

The normal approach creating socket connections is:

Server side:

  1. Create a socket
  2. Bind the socket to a specyfic interface and port
  3. Let the socket listen.
  4. in a loop, try to accept connections to the socket
  5. handle the connection

Client side:

  1. Create a client_socket
  2. Try to connect to the server socket.

Some information about network-programming in python: here and here

Upvotes: 0

Related Questions