Universal Robots Forum

I can never get the robot state from TCP/IP

I am using python, UR5 software 5.4. the tcp IP is

    self.tcp_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    self.tcp_socket.connect((self.tcp_host_ip, self.tcp_port))
    state_data = self.tcp_socket.recv(2048)

If I peak at state_data, this should give me the message type. It is always 20.

But, it should be 16 if I want to read the robot state message. How do i do it?

If I call recv multiple times, it is still never 16.

(Pdb) self.tcp_socket.recv(2048)[4]
37
(Pdb) self.tcp_socket.recv(2048)[4]
39
(Pdb) self.tcp_socket.recv(2048)[4]
158
(Pdb) self.tcp_socket.recv(2048)[4]
209
(Pdb) self.tcp_socket.recv(2048)[4]
0
(Pdb) self.tcp_socket.recv(2048)[4]
0
(Pdb) self.tcp_socket.recv(2048)[4]
195
(Pdb) self.tcp_socket.recv(2048)[4]
0
(Pdb) self.tcp_socket.recv(2048)[4]
86
(Pdb) self.tcp_socket.recv(2048)[4]
191
(Pdb) self.tcp_socket.recv(2048)[4]
57
(Pdb) self.tcp_socket.recv(2048)[4]
0
(Pdb) self.tcp_socket.recv(2048)[4]
0
(Pdb) self.tcp_socket.recv(2048)[4]
225
(Pdb) self.tcp_socket.recv(2048)[4]
0
(Pdb) self.tcp_socket.recv(2048)[4]
1
(Pdb) self.tcp_socket.recv(2048)[4]
0
(Pdb) self.tcp_socket.recv(2048)[4]
133
(Pdb) self.tcp_socket.recv(2048)[4]
66
(Pdb) self.tcp_socket.recv(2048)[4]
7
(Pdb) self.tcp_socket.recv(2048)[4]
0
(Pdb) self.tcp_socket.recv(2048)[4]
0
(Pdb) self.tcp_socket.recv(2048)[4]
0

So the question is, how can I get the robot state? Message type == 16