# Socket Communication in generateScript()

**URL:** <https://forum.universal-robots.com/t/socket-communication-in-generatescript/10747>\
**Category:** Robot Communication\
**Created:** [December 11, 2020, 2:14pm UTC](https://forum.universal-robots.com/t/socket-communication-in-generatescript/10747 "2020-12-11T14:14:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![anon5706138](https://avatars.discourse-cdn.com/v4/letter/a/90ced4/32.png) [@anon5706138](https://forum.universal-robots.com/u/anon5706138)\
**Post date:** [December 11, 2020, 2:14pm UTC](https://forum.universal-robots.com/t/socket-communication-in-generatescript/10747/1 "2020-12-11T14:14:55Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![sko](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.universal-robots.com/sko/32/573_2.png) [@sko](https://forum.universal-robots.com/u/sko)\
**Post date:** [December 14, 2020, 2:58pm UTC](https://forum.universal-robots.com/t/socket-communication-in-generatescript/10747/2 "2020-12-14T14:58:46Z")

</div>

This could be helpful for your case:

> [@URCap Sample: URCap-ScriptCommunicator](https://forum.universal-robots.com/t/urcap-scriptcommunicator/8460):
>
> Dear community, I have forked Jacobs URCap-ScriptCommunicator and added the framework to proxy URScript functions from Java. So far it is only a subset of the functions that are implemented yet. I hope you will add the functions when you need is there and then share it with the rest of the community! Description of functionality: This sample implements a Java class to: Send URScript commands for immediate execution by URControl Extract a variable from URScript to Java Proxy URScript functio…
