# Secondary Client Issue

**URL:** <https://forum.universal-robots.com/t/secondary-client-issue/1891>\
**Category:** Robot Communication\
**Created:** [April 17, 2018, 8:43am UTC](https://forum.universal-robots.com/t/secondary-client-issue/1891 "2018-04-17T08:43:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![matthew.pearson](https://avatars.discourse-cdn.com/v4/letter/m/35a633/32.png) [@matthew.pearson](https://forum.universal-robots.com/u/matthew.pearson)\
**Post date:** [April 17, 2018, 8:43am UTC](https://forum.universal-robots.com/t/secondary-client-issue/1891/1 "2018-04-17T08:43:15Z")

</div>

Hi

I would appreciate some help with sending multiple lines of script from a button in our URCap. We can send a single line like a popup or setting an output but multiple lines are not working. We are using the “ClientSendScript” class. To try and find the problem I am simply sending two lines of script within the def end statement but only the second line works. When I’ve tried more than two lines it is still only the last line that is executed.

In the screenshot below you can see the command that is sent each time the button is pressed in the terminal and the effect on the output state in Polyscope. What am I doing wrong? I’m sure it must be something simple but I’ve been trying for hours without luck.

 ![screen](https://us1.discourse-cdn.com/flex020/uploads/universal_robots/original/1X/69d2af1bd9d2def2578b62a00cdddcfa08df4fc7.png)

I can see from here

> [@Sending multiple Commands over Tcp](https://forum.universal-robots.com/t/sending-multiple-commands-over-tcp/1748/2):
>
> You will have to wait for the robot to execute the current command and then send the new one.

that others have had this issue but using a def statement should be the answer but it’s not working

Here is the method that produces the string that goes to the script sending class

![screen2](https://us1.discourse-cdn.com/flex020/uploads/universal_robots/original/1X/77edc527fd64b2deb4ddfc864b2e80e24c0f017f.png)

And here is the sending function

![screen3](https://us1.discourse-cdn.com/flex020/uploads/universal_robots/original/1X/5e4d6541ee6aebfeb794f6141accb538608132d2.png)

Thank you for your time

Regards

Matthew

---

<div class="post-metadata">

**Author:** ![mmi](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.universal-robots.com/mmi/32/691_2.png) [@mmi](https://forum.universal-robots.com/u/mmi)\
**Post date:** [April 17, 2018, 12:24pm UTC](https://forum.universal-robots.com/t/secondary-client-issue/1891/2 "2018-04-17T12:24:38Z")

</div>

You shouldn’t use writeUTF function - according to documentation it adds lenght before string. You should use

```
out.writeBytes(thisCommand);
out.write(thisCommand.getBytes("US-ASCII"));

```

Also remember about indentation rules when you send scripts directly to the socket. You can find these in latest URScript documentation in section 1.2.

---

<div class="post-metadata">

**Author:** ![matthew.pearson](https://avatars.discourse-cdn.com/v4/letter/m/35a633/32.png) [@matthew.pearson](https://forum.universal-robots.com/u/matthew.pearson)\
**Post date:** [April 17, 2018, 1:47pm UTC](https://forum.universal-robots.com/t/secondary-client-issue/1891/3 "2018-04-17T13:47:41Z")

</div>

Thank you very much. That worked very well
