# Connection Timed Out using TCP/IP Socket

**URL:** <https://forum.universal-robots.com/t/connection-timed-out-using-tcp-ip-socket/34934>\
**Category:** Robot Communication\
**Created:** [June 26, 2024, 11:13am UTC](https://forum.universal-robots.com/t/connection-timed-out-using-tcp-ip-socket/34934 "2024-06-26T11:13:55Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![eem25](https://avatars.discourse-cdn.com/v4/letter/e/b5ac83/32.png) [@eem25](https://forum.universal-robots.com/u/eem25)\
**Post date:** [June 26, 2024, 11:13am UTC](https://forum.universal-robots.com/t/connection-timed-out-using-tcp-ip-socket/34934/1 "2024-06-26T11:13:55Z")

</div>

Hello there,

i’m new to UR and i’m testing my connection to a UR10. I have setup a program THAT WORKS from which i can send script and commands to the UR via socket (IP of my UR is static on a ethernet network, port is 30002, entry point is my machine). I have a script which tries to connect to a another process i have setup to listen the UR request. The code for openning the socket is something like this:

```auto
  $ 1 "port≔12345"
  global port=21
  $ 2 "ip_addr≔'169.254.150.55'"
  global ip_addr="169.254.150.55"
  $ 3 "socket≔socket_open(ip_addr,port,'conn')"
  global socket=socket_open(ip_addr,port,"conn")
  $ 4 "Loop socket≟ False "
  while (socket == False ):
    $ 5 "socket≔socket_open(ip_addr,port,'conn')"
    global socket=socket_open(ip_addr,port,"conn")
  end

```

And the python listener goes like this:

```auto
import socket
import time

HOST = "localhost" 
PORT = 21 

print("Starting Program")
count = 0

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((HOST, PORT)) # Bind to the port 
s.listen(5) # Now wait for client connection.
c, addr = s.accept() # Establish connection with client.
print(f"Connection from: {addr}")

```

There is more code but this all that is needed. I tried changing the HOST to 127.0.0.1 and the IP on the ethernet interface . Any idea why is giving me a timeout connection? Also i have a wireshark set up and this is what it shows me:

 ![image](https://us1.discourse-cdn.com/flex020/uploads/universal_robots/original/2X/0/0b7523744ed8b44bca96bde24bd020e24e1f89dc.png)

UR IP: 169.254.177.55  
Machine IP: 169.254.150.55  
Listener Port: 21

NOTE: the script that runs the program on the UR that tries to establish a connection i tried it from running it from the teach pendant directly and from sending through my tool that works (so the UR is on Remote mode).

Thx in advance

---

<div class="post-metadata">

**Author:** ![forbech](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.universal-robots.com/forbech/32/902_2.png) [@forbech](https://forum.universal-robots.com/u/forbech)\
**Post date:** [June 27, 2024, 11:04am UTC](https://forum.universal-robots.com/t/connection-timed-out-using-tcp-ip-socket/34934/2 "2024-06-27T11:04:30Z")

</div>

Maybe same problem here:

> [@RTDE Connection Error \[WinError 10054\] Connection got closed from the Remotehost](https://forum.universal-robots.com/t/rtde-connection-error-winerror-10054-connection-got-closed-from-the-remotehost/32985):
>
> Hallo, Setup: UR5e, RTDE Python Connection with Ethernet Cable and IP Port 300004 The robot and a laptop are connected with an Ethernet cable, and I tested my program which worked fine. After a bunch of test runs, it often started to close the connection as if the robot wasn’t connected anymore. Because there is a long process in Python, I increased the watchdog timeout in the UR Polyscope. That worked, but without changes, it started to give me the same error mid-running the program: [WinEr…

---

<div class="post-metadata">

**Author:** ![eem25](https://avatars.discourse-cdn.com/v4/letter/e/b5ac83/32.png) [@eem25](https://forum.universal-robots.com/u/eem25)\
**Post date:** [June 27, 2024, 11:53am UTC](https://forum.universal-robots.com/t/connection-timed-out-using-tcp-ip-socket/34934/3 "2024-06-27T11:53:51Z")

</div>

I’ll try it on monday but i think it won’t give me a result as the problem is that the UR, acting as a client, won’t connect to the machine but doing it the other way around it works. Eitherway, thanks and i will keep the post updated with the results.

---

<div class="post-metadata">

**Author:** ![lxop](https://avatars.discourse-cdn.com/v4/letter/l/8491ac/32.png) [@lxop](https://forum.universal-robots.com/u/lxop)\
**Post date:** [July 3, 2024, 4:04am UTC](https://forum.universal-robots.com/t/connection-timed-out-using-tcp-ip-socket/34934/4 "2024-07-03T04:04:24Z")

</div>

The problem is that your Python program isn’t listening on the ethernet interface, it is only listening on the loopback interface (`"localhost"` or `"127.0.0.1"`). The solution is to change `HOST` to `""`, which will listen on all interfaces, or `"169.254.150.55"` which will listen only on the ethernet interface connected to the robot.

See the second bullet point on [this page](https://docs.python.org/3/library/socket.html#socket-families).
