# URScript 3.12 socket\_read\_string reads multiple strings?

**URL:** <https://forum.universal-robots.com/t/urscript-3-12-socket-read-string-reads-multiple-strings/6870>\
**Category:** URScript\
**Created:** [April 2, 2020, 4:32pm UTC](https://forum.universal-robots.com/t/urscript-3-12-socket-read-string-reads-multiple-strings/6870 "2020-04-02T16:32:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![joao1](https://avatars.discourse-cdn.com/v4/letter/j/e95f7d/32.png) [@joao1](https://forum.universal-robots.com/u/joao1)\
**Post date:** [April 2, 2020, 4:32pm UTC](https://forum.universal-robots.com/t/urscript-3-12-socket-read-string-reads-multiple-strings/6870/1 "2020-04-02T16:32:34Z")

</div>

In the URScript 3.12 documentation.  
Under socket\_read\_string it reads the following:

> By using the “prefix” and “suffix” it is also possible send multiple string to  
> the controller at once, because the suffix defines where the message  
> ends. E.g. sending “\>hello\<\>world\<” and calling this script function with  
> the prefix=“\>” and suffix=“\<”.

Does this mean that the function returns an array of strings delimited by prefix and suffix?  
Or does it read the socket buffer until the first suffix is found, meaning you would be able to use “socket\_read\_string” repeatedly on one received packet to get all the message’s parts?

I find the wording very confusing too.  
Can anyone clarify what this function does please?

---

<div class="post-metadata">

**Author:** ![mbush](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.universal-robots.com/mbush/32/76_2.png) [@mbush](https://forum.universal-robots.com/u/mbush)\
**Post date:** [April 3, 2020, 2:43pm UTC](https://forum.universal-robots.com/t/urscript-3-12-socket-read-string-reads-multiple-strings/6870/2 "2020-04-03T14:43:54Z")

</div>

I was curious what this did too so I wrote a simple server and a test program in Polyscope.

Here is the server that I wrote in node.js:

```
"use strict";
var net = require("net");

let server = net
  .createServer((sock) => {
    sock.on("connect", (data) => {});

    sock.on("data", (data) => {
      console.log(data.toString());
      sock.write(">Hello<>World<");
    });
  })
  .listen(2115);

```

Here is the Polyscope program that connects and reads from the server

 ![image](https://us1.discourse-cdn.com/flex020/uploads/universal_robots/original/2X/8/825deca2e3332cf10509c9184e01ce8e01e7edea.png)

What this does is actually set var\_1 to “Hello” and var\_2 to “World”. So basically with a single send from the server I am able to get set the value of multiple variables from that single server write. So just playing around I changed the command that was written back from the server to `sock.write(">Hello<>World<>from<>node<")` and then added two more variables and this is what I get now

![image](https://us1.discourse-cdn.com/flex020/uploads/universal_robots/original/2X/6/63733ad557458738e9cc067114b253e9f5005167.png)

Hope that helps clarify what is going on and I learned something new today myself!

---

<div class="post-metadata">

**Author:** ![joao1](https://avatars.discourse-cdn.com/v4/letter/j/e95f7d/32.png) [@joao1](https://forum.universal-robots.com/u/joao1)\
**Post date:** [April 7, 2020, 11:56am UTC](https://forum.universal-robots.com/t/urscript-3-12-socket-read-string-reads-multiple-strings/6870/3 "2020-04-07T11:56:26Z")

</div>

This is exactly what I wanted then.  
Amazing response.  
Thank you!
