Movej over TCP/IP does not work

I am trying to move the arm by sending commands over TCP/IP via socket library. The digital pin commands work fine, but I am unable to move the arm. Can anyone provide a working example please?

Make sure you are in remote mode.

I am in remote mode. It is fixed when I introduced a delay to the code. Why does this happen?

Now the same code stopped working. I am really confused. Here is the all code:

import socket
import time

PORT = 30001
HOST = "192.168.1.20"

def client():
    s = socket.socket()
    s.connect((HOST, PORT))
    
    while True:
        try:
            command = "set_digital_out(2, True)\n"
            s.send(command.encode('utf-8'))
            received_data = s.recv(1024)
            time.sleep(1)
            command = "set_digital_out(2, False)\n"
            s.send(command.encode('utf-8'))
            received_data = s.recv(1024)
            time.sleep(1)
            command = "movej([-1.5708, -1.5708, -1.5708, -0, 1.5708, -4.71241], a=1.2, v=1.2)\n"
            s.send(command.encode('utf-8'))
            received_data = s.recv(1024)
            time.sleep(5)
            command = "movej([-1.5708, -1.5708, -1.5708, -1.5708, 1.5708, -4.71241], a=1.2, v=1.2)\n"
            s.send(command.encode('utf-8'))
            received_data = s.recv(1024)
            time.sleep(5)
            # command = "twofg_grip_ext(24.5, 50, 100)\n"
            # s.send(command.encode('utf-8'))
            # time.sleep(5)
        except KeyboardInterrupt:
            break
    s.close()

if __name__ == '__main__':
    client()

Hi, if no sleep between move commands, the port will always do the latest one.

Have tried the code posted, worked well with URSim. any error reported when it is not working?

It was the cable. I changed the cable now it works. Do you have any idea how I can control 2FG7 gripper via TCP/IP?