# How to communicate with Virtual Controller through localhost

**URL:** <https://tech-community.robotics.abb.com/t/how-to-communicate-with-virtual-controller-through-localhost/7217>\
**Category:** RobotStudio\
**Tags:** python-rs-commu\
**Created:** [June 13, 2016, 10:26am UTC](https://tech-community.robotics.abb.com/t/how-to-communicate-with-virtual-controller-through-localhost/7217 "2016-06-13T10:26:51Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jackyliang](https://avatars.discourse-cdn.com/v4/letter/j/838e76/32.png) [@jackyliang](https://tech-community.robotics.abb.com/u/jackyliang)\
**Post date:** [June 13, 2016, 10:26am UTC](https://tech-community.robotics.abb.com/t/how-to-communicate-with-virtual-controller-through-localhost/7217/1 "2016-06-13T10:26:51Z")

</div>

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](https://github.com/robotics/open_abb/blob/fuerte-devel/abb_node/packages/abb_communications/abb.py) 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

---

<div class="post-metadata">

**Author:** ![John\_Verheij](https://dub1.discourse-cdn.com/flex005/user_avatar/tech-community.robotics.abb.com/john_verheij/32/1724_2.png) [@John\_Verheij](https://tech-community.robotics.abb.com/u/John_Verheij)\
**Post date:** [June 15, 2016, 9:19am UTC](https://tech-community.robotics.abb.com/t/how-to-communicate-with-virtual-controller-through-localhost/7217/2 "2016-06-15T09:19:20Z")

</div>

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

```auto
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...")

```

```auto
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:

```auto

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

```
