Socket Communication in generateScript()

Hello,

I am trying to get the values of get_actual_tcp_pose() and modbus_get_signal_status in Java.

So I am trying to push these 2 variables to the Sockets like this:

            String RETURN_IP = "127.0.0.1";
            int RETURN_PORT = 30003;
            String RETURN_SOCKETNAME = "\"EXPORT_SOCKET\"";
            writer.appendLine("socket_open(\""+RETURN_IP+"\","+RETURN_PORT+","+RETURN_SOCKETNAME+")");
            writer.appendLine("global float_val = get_actual_tcp_pose()");
            
            writer.appendLine("socket_send_string("+"float_val"+","+RETURN_SOCKETNAME+")");                
            writer.appendLine("socket_close("+RETURN_SOCKETNAME+")");

But when I try to read them like this:

            Socket returnSocket = new Socket("127.0.0.1", 30003);
            
            BufferedReader read1 = new BufferedReader(new InputStreamReader(returnSocket.getInputStream()));
            input1 = read1.readLine();
            
            read1.close();
            returnSocket.close();

It says java.net.ConnectException: Connection refused (Connection refused)

On the line: Socket returnSocket = new Socket(“127.0.0.1”, 30003);

Can not we get variables from URScript when the program is running?

Thank you,

MB

This could be helpful for your case:

1 Like