How to communicate with Virtual Controller through localhost

Is there a way to communicate with a running virtual controller in RobotStudio through localhost? I’m looking for ways to send commands over “ethernet” to a localhost port to a robot in simulation.

More specifically, I’m trying to use this python script to setup the connection. I’ve tried setting the ip to ‘localhost’ and ‘127.0.0.1’, and have also tried setting the ports to every single port that’s being listened on by the process RobVC.exe, but with no luck. The errors I’m getting are either one of the following:

  • No connection could be made because the target machine actively refused it
  • An existing connection was forcibly closed by the remote host
    I’m on Windows 10 and using RobotStudio 6.03. The virtual robot I’m trying to connect to is the

The first error occur when one side is trying to make a connection, but no one accepts the connection…
The second error occur when a connection is made, but one side closes the connection (while the connection is still in use)…

Furthermore it depends on if you are using Python3x or Python2x. For example the type ‘string’ is not the same…

I created an example with python 3.4.4 and RobotStudio 6.03

import socket

sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect(('127.0.0.1', 55555))

sock.send(bytes("Hoi", 'UTF-8'))

print(sock.recv(4096).decode('UTF-8'))

# Wait till user press 'Enter' to exit
input("Press Enter to continue...")

MODULE Module1
    PROC main()
        VAR socketdev server_socket;
        VAR socketdev client_socket;
        VAR string receive_string;
        VAR string client_ip;

        SocketCreate server_socket;
        SocketBind server_socket, "127.0.0.1", 55555;
        SocketListen server_socket;

        ! Waiting for a connection request
        WHILE TRUE DO
            SocketAccept server_socket, client_socket\ClientAddress:=client_ip\Time:=WAIT_MAX;
            SocketReceive client_socket \Str := receive_string;
            SocketSend client_socket \Str := "Hello client with ip-addres " +client_ip;
            SocketClose client_socket;
        ENDWHILE
    ERROR
        RETRY;
    UNDO
        SocketClose server_socket;
        SocketClose client_socket;
        
    ENDPROC
ENDMODULE

This will give me the following output:


Hello client with ip-addres 127.0.0.1
Press Enter to continue...