Just to clear up why the first sample didn’t work - it’s a mix up between what you would send to the client interfaces (receive urscript commands on ports 30001-30003) and the dashboard server (receive plain text commands on port 29999), and also not receiving any data from the socket for a reply.
The def program() part is URScript that you would use when sending a whole program to one of the client interface ports, much like that shown here:
This is not necessary for the dashboard server. I would assume the reason the play and pause worked is because the \n newline characters meant the dashboard server interpreted it as 3 separate commands and only recognized the middle part.
So as you’ve discovered just sending the dashboard commands listed at the link below with \n newline at the end is sufficient for them to be received by the dashboard server. The .encode() encoding of the string is also not necessary.
Then if you want to actually get some feedback from the you need to receive from the socket as you have done with rcvd = s.recv(4096). I think the recv command will also wait until it receives something, so the sleep command after it shouldn’t be necessary either.