Universal Robots Forum

URScript 3.12 socket_read_string reads multiple strings?

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?

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

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

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

1 Like

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