# Can urcap send and execute ur script within the program node?

**URL:** <https://forum.universal-robots.com/t/can-urcap-send-and-execute-ur-script-within-the-program-node/378>\
**Category:** URCap Development\
**Created:** [November 25, 2016, 4:40am UTC](https://forum.universal-robots.com/t/can-urcap-send-and-execute-ur-script-within-the-program-node/378 "2016-11-25T04:40:13Z")\
**Posts on this page:** 1\
**Showing post:** 12

<div class="post-metadata">

**Author:** ![jbm](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.universal-robots.com/jbm/32/614_2.png) [@jbm](https://forum.universal-robots.com/u/jbm)\
**Post date:** [June 27, 2017, 2:43pm UTC](https://forum.universal-robots.com/t/can-urcap-send-and-execute-ur-script-within-the-program-node/378/12 "2017-06-27T14:43:26Z")

</div>

In this example, a custom popup is sent to the secondary client, when the method `createPopup(message)` is called.

```auto
package com.ur.urcap.yourUrCap.impl;

import java.io.DataOutputStream;
import java.io.IOException;
import java.net.Socket;

public class clientSendScript {
	
	public clientSendScript() { }
	
	// localhost IP
	private String TCP_IP = "127.0.0.1";
	// Port for secondary client
	private int TCP_port = 30002;
	
	// Public method to send popup script to client interface
	public void createPopup(String message){
		sendToSecondary("popup(\""+message+"\")");
	}
	
	// Internal method that sends script to client
	private void sendToSecondary(String command){
		try{
			// Create a new Socket Client
			Socket sc = new Socket(TCP_IP, TCP_port);
			if (sc.isConnected()){
				System.out.println("Connected to UR Secondary Client");
			}
			
			// Create stream for data
			DataOutputStream out;
			out = new DataOutputStream(sc.getOutputStream());
			
			// Wrap command in "def" and "end"
			String thisCommand = "def myCustomCode():\n "+command+"\n end\n";
			
			// Send command
			out.writeUTF(thisCommand);
			System.out.println("Send this: "+thisCommand);
			out.flush();

			// Perform housekeeping 
			out.close();
			sc.close();
			System.out.println("Disconnected from UR Secondary Client");
		} 
		catch (IOException e){
			System.out.println(e);
		}
	}
}

```

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

---

_[View the full topic](https://forum.universal-robots.com/t/can-urcap-send-and-execute-ur-script-within-the-program-node/378)._
