Triggering actions through TCP/IP


we purchased one of your great robots (UR10e) for exchanging samples in some measurement setup. To fulfill this task it has to communicate with several other devices, to open some containment for example and avoid collisions. Some alternative subprograms will be necessary as well, for example to “clean” the gripper.
I went through your free e-learning modules, read through different articles and forum threads. The basic functionality seems not to be the problem, but I still don’t get how controlling the programm from some external machine should work.

I tried out three different ways to trigger actions. All three are based on a main event loop that will call subprograms.

  • The first try was to call the subprograms directly by sending the call to port 30001. This seems to work for single line instructions, but not for subprogram calls.
  • The second was to set a variable through port 30001, 30002 or 30020. But the scope seems to be wrong here. Even if the identifier was declared global and is part of the running program, this doesn’t seem to be able to see the changes.
  • The third way, was to open a socket from the robot side and send instructions through that. Somehow my Python server program and the UR controller seem to disagree on how to handle TCP connections, because I never managed to send more then one instruction through it, before it gets either closed or reset.

I’m sure I’m missing something basic here. What is a smart way of triggering actions through TCP/IP from a linux box? What would be your approach?

There are two other things that make me struggle:

  • How can I write programs on a real editor/keyboard and import them to the robot later? If I save them as “script” and include them to the program as script-file, this looks anything but clearly arranged in the controllers view. Plus “save all” will add all kind of stuff to it, that might even render is faulty.
  • Some programs are going to pause at various points for unclear reasons. The log is no help here, it just says “Program … paused” without giving any details or even line numbers.

Please excuse me if these are newbie problems. In fact I am absolutely new to UR, though this is not the first robot I’m programming.

Hi @jan.meyer

the basics for the communications via our Client Interfaces can be found in the this Support Article. We also provide a sample for using the UR Script Socket to communicate with a different partner in the network.

What is important to know is, that sending a UR Script command via a client Interface to the robot, has the same effect as pressing the play button in Polyscope. Only that not the Program created in the Teach Pendant will be executed, but the UR Script sent to the robot. In our Script Manual you can find some additional insights in how UR Script is interpreted through the Client Interface.

Here a quick summary of points to keep in mind:

  • For more then one UR Script line to be executed via a Client Interface it needs to be surrounded by a function definition ( e.g. def myTest(): ) and an end statement.
  • To accept external Script commands the Robot must be in Remote Mode before the connection is established.
  • Sending a Script command to the robot during a running program, the program will stop immediately and the sent Script will be executed. There are exception if you are using a Secondary Program or the Interpreter Mode (see the Script Manual for more details)

For creating UR Script Code outside of Polyscope I can recommend using Visual Studio Code in combination with the URScript extension.

Using Python the following minimal code samples did work for me in the past:

def connectToClientInterface(HOST, PORT, message):
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.connect((HOST, PORT))    
    data = s.recv(1024)
        print 'Received', repr(data)
        data = s.recv(1024)
def connectToClientInterface_SendFile(HOST, PORT, filePath):
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.connect((HOST, PORT))
    f = open (filePath, "rb")   
    l =
    while (l):
        l =

Hope this helps you out!


Hi @sko ,

thanks a lot. It helped me in so far, that I was immediately able to submit a script which was executed:

import socket

ds_ip = ""
ds_port = 60021
ur_ip = ""
ur_port = 30001

ur_client = """def URClient():
  global counter=0
  global interval=0

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((ur_ip, ur_port))
s.send(bytes(ur_client, "ascii"))

When I start the script, I can see DO2 blinking. Btw., for now I’m back to URSim. Funny enough, if I exchange the UR script in the above with the following, this seems to be never executed.

ur_client = """def URClient():
  global open=socket_open("{0}",60021)
  while (open ==  False):
    global open=socket_open("{0}",60021)
  global counter=0
  while (True):
    recv = socket_read_list(4)
    if recv[0] == 0:
      textmsg("socket", " timeout")

Wireshark shows me, that there are no connection attempts. If I start the same script from within Polyscope, a connection is established “urc\n” gets send, but then the socket gets closed for some reason.

So, I didn’t really progress on my main issue: How can I set up a connection from a Linux box and have some call-response-style communication through it with the UR controller?

I found some silly errors in my test scripts, both UR and Python, which caused that the socket got closed after every request/reply pair. I think my problem is solved.

I open a server socket on the Linux box, connect to it from the robot and have my own tiny command language send over it.

Thanks for your help.

1 Like