This is the code I’ve used based on TCP/IP socket communication via URScript. Just save the files individually as I can’t upload yet (new user limitations):
URClient.script
def URClient():
  global _hidden_verificationVariable=0
  step_count_f072f558_bbd1_4f1d_a96f_34c602bc3ccb = 0.0
  thread Step_Counter_Thread_8705b908_ca4e_4d49_8a65_fc967e5a3caf():
    while (True):
      step_count_f072f558_bbd1_4f1d_a96f_34c602bc3ccb = step_count_f072f558_bbd1_4f1d_a96f_34c602bc3ccb + 1.0
      sync()
    end
  end
  run Step_Counter_Thread_8705b908_ca4e_4d49_8a65_fc967e5a3caf()
  set_standard_analog_input_domain(0, 1)
  set_standard_analog_input_domain(1, 1)
  set_tool_analog_input_domain(0, 1)
  set_tool_analog_input_domain(1, 1)
  set_analog_outputdomain(0, 0)
  set_analog_outputdomain(1, 0)
  set_input_actions_to_default()
  set_target_payload(2.000000, [0.000000, 0.000000, 0.000000], [0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000])
  set_safety_mode_transition_hardness(0)
  set_tool_communication(False, 115200, 0, 1, 1.5, 3.5)
  set_tool_output_mode(0)
  set_tool_digital_output_mode(0, 1)
  set_tool_digital_output_mode(1, 1)
  set_tool_voltage(0)
  set_gravity([0.0, 0.0, 9.82])
  set_tcp(p[0.0,0.0,0.0,0.0,0.0,0.0])
  $ 2 "BeforeStart"
  $ 3 "open≔socket_open('127.0.0.1',29999)"
  global open=socket_open("127.0.0.1",29999)
  $ 4 "Loop open≟ False "
  while (open ==   False  ):
    $ 5 "open≔socket_open('127.0.0.1',29999)"
    global open=socket_open("127.0.0.1",29999)
  end
  while (True):
    $ 6 "Robot Program"
    $ 7 "reply≔socket_read_line()"
    global reply=socket_read_line()
    $ 8 "sendToServer≔'is in remote control'"
    global sendToServer="is in remote control"
    $ 9 "Loop"
    while (True):
      $ 10 "socket_send_line(sendToServer)"
      socket_send_line(sendToServer)
      $ 11 "Wait: 1.0"
      sleep(1.0)
      $ 12 "reply≔socket_read_line()"
      global reply=socket_read_line()
      $ 13 "If reply≟'true'"
      if (reply == "true"):
        $ 14 "Set Remote= True "
        write_output_boolean_register(0,   True  )
      else:
        $ 15 "Else" "noBreak"
        $ 16 "Set Remote= False "
        write_output_boolean_register(0,   False  )
      end
      $ 17 "reply≔''"
      global reply=""
    end
  end
end
URClient.txt
 Program
   Variables Setup
   BeforeStart
     open≔socket_open("127.0.0.1",29999)
     Loop open≟ False 
       open≔socket_open("127.0.0.1",29999)
   Robot Program
     reply≔socket_read_line()
     sendToServer≔"is in remote control"
     Loop
       socket_send_line(sendToServer)
       Wait: 1.0
       reply≔socket_read_line()
       If reply≟"true"
         Set Remote= True 
       Else
         Set Remote= False 
       reply≔""