UDP socket communication with virtual irc5

Hi, I am trying to send udp between virtual IRC5 and external python script but hitting problems. I am having trouble getting udp sockets to connect and communicate in to or out of robot studio. Firstly I am not that familiar with windows or robot studio which may not be helping. Initially I couldn’t ping the robot studio machine from my unix machine. I played with the firewall to allow pinging and udp on all ports and the ping server responded. Next I checked that I could send udp between the windows PC and unix using python scripts. This works.

I have robot studio set up with an IRB1200 and IRC5 virtual controller with PC interface enabled. Using the following rapid code as a client send example;

MODULE socket_server

VAR socketdev serverSocket;
VAR socketdev clientSocket;
VAR string data;

PROC main()

SocketCreate clientSocket;

SocketConnect clientSocket, “10.0.1.29”, 2021;
SocketSend clientSocket \Str:=“Hello server”;

ENDPROC

ENDMODULE


Or as a server receive example;

MODULE socket_server

VAR socketdev serverSocket;
VAR socketdev clientSocket;
VAR string data;

PROC main()

SocketCreate serverSocket;

SocketBind serverSocket, “10.0.1.29”, 2020;
SocketListen serverSocket;

SocketAccept serverSocket, clientSocket,\Time:=WAIT_MAX;

ERROR

IF ERRNO=ERR_SOCK_TIMEOUT THEN
RETRY;

ELSEIF ERRNO=ERR_SOCK_CLOSED THEN
SocketClose clientSocket;
SocketClose serverSocket;
SocketCreate serverSocket;
SocketBind serverSocket, “127.0.0.1”, 5004;
SocketListen serverSocket;
SocketAccept serverSocket,clientSocket,\Time:=WAIT_MAX;

RETRY;

ELSE
stop;

ENDIF

ENDPROC

ENDMODULE


The error I get when I try to connect the client on the virtual controller and send udp out:

*** SocketConnect clientSocket, “10.0.1.29”, 2021;

41574: Socket error
Description
Task: T_ROB1.
The socket must be created before it can be used in any socket instruction.
Program ref: /socket_server/main/SocketConnect/11.
Causes
The reason for this error is one of the following:

  1. Socket not created at all.
  2. PP movements has been done.
  3. Start of program after power fail.
  4. The socket has been closed after SocketCreate.
    Actions
    Insert a SocketCreate instruction at a suitable place in the program before the socket is used.
    Recovery: ERR_SOCK_CLOSED.

When I create the server on the virtual controller it just hangs on SocketAccept serverSocket, clientSocket,\Time:=WAIT_MAX; until it times out.

Is there anything obvious I have missed out on the set up? Is windows firewall getting in the way? Im totally stumped after a day of trying to get this to work. Any advice would be greatly appreciated.

The server code I pasted is actually missing the socket receive line:

MODULE socket_server

VAR socketdev serverSocket;
VAR socketdev clientSocket;
VAR string data;

PROC main()
SocketCreate clientSocket;

SocketCreate serverSocket;
SocketBind serverSocket, “10.0.1.29”, 2020;

SocketListen serverSocket;

SocketAccept serverSocket, clientSocket,\Time:=WAIT_MAX;

SocketReceive serverSocket \Str:=data;
SocketSend clientSocket \Str:=“received”;

SocketClose clientSocket;
SocketClose serverSocket;

ERROR

IF ERRNO=ERR_SOCK_TIMEOUT THEN
RETRY;

ELSEIF ERRNO=ERR_SOCK_CLOSED THEN
SocketClose clientSocket;
SocketClose serverSocket;
SocketCreate serverSocket;
SocketBind serverSocket, “127.0.0.1”, 5004;
SocketListen serverSocket;
SocketAccept serverSocket,clientSocket,\Time:=WAIT_MAX;

RETRY;

ELSE
stop;

ENDIF

ENDPROC

ENDMODULE