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

I had tried to establish the socket communication within java using localhost IP address 127.0.0.1 and port 30001,30002,30003. I test by press the button and sending data stream ‘popup(“Hello World”)’ and except it to show the popup window for Hello World. But after i pressed the button, the popup does not appear. I output show text to screen to show me the progress and it shows that the code execute until close socket.Somehow the URScript sent was not responding.

here are the code that I modify from helloworld sample

package com.ur.urcap.examples.helloworld.impl;

import com.ur.urcap.api.contribution.ProgramNodeContribution;
import com.ur.urcap.api.domain.URCapAPI;
import com.ur.urcap.api.domain.data.DataModel;
import com.ur.urcap.api.domain.script.ScriptWriter;
import com.ur.urcap.api.ui.annotation.Input;
import com.ur.urcap.api.ui.annotation.Label;
import com.ur.urcap.api.ui.component.InputEvent;
import com.ur.urcap.api.ui.component.InputButton;
import com.ur.urcap.api.ui.component.InputTextField;
import com.ur.urcap.api.ui.component.LabelComponent;

import java.io.;
import java.net.
;

public class HelloWorldProgramNodeContribution implements ProgramNodeContribution{
private static final String NAME = “name”;

private final DataModel model;
private final URCapAPI api;
private String cachedPopupMessage = "";
private String cachedPopupMessage1 = "";
private String cachedPopupMessage2 = "";
private String cachedPopupMessage3 = "";
private String cachedPopupMessage4 = "";
private String cachedPopupMessage5 = "";
private String cachedPopupMessage6 = "";
private String cachedPopupMessage7 = "";

private Socket connection;
private PrintWriter output;

public HelloWorldProgramNodeContribution(URCapAPI api, DataModel model) {
	this.api = api;
	this.model = model;
}

@Input(id = "yourname")
private InputTextField nameTextField;

@Label(id = "titlePreviewLabel")
private LabelComponent titlePreviewLabel;

@Label(id = "messagePreviewLabel")
private LabelComponent messagePreviewLabel;
@Label(id = "messagePreviewLabel1")
private LabelComponent messagePreviewLabel1;
@Label(id = "messagePreviewLabel2")
private LabelComponent messagePreviewLabel2;
@Label(id = "messagePreviewLabel3")
private LabelComponent messagePreviewLabel3;
@Label(id = "messagePreviewLabel4")
private LabelComponent messagePreviewLabel4;
@Label(id = "messagePreviewLabel5")
private LabelComponent messagePreviewLabel5;
@Label(id = "messagePreviewLabel6")
private LabelComponent messagePreviewLabel6;
@Label(id = "messagePreviewLabel7")
private LabelComponent messagePreviewLabel7;

@Input(id = "button")
private InputButton button;

@Input(id = "button")
public void onButton(InputEvent event) throws InterruptedException{
	if(event.getEventType()==InputEvent.EventType.ON_PRESSED){
		startRun();
	}
}

public void startRun() throws InterruptedException{
	try{
		connectToServer();
		setupStreams();
		//sendScript("popup(\"Hello World\")");
		sendScript("popup(\"Hello World\")");
		closeSocket();
	}catch(EOFException eofException){
		
	}catch(IOException ioException){
		
	}
}

private void connectToServer() throws IOException{
	setName("Attempting.....");
	updatePopupMessageAndPreview();
	connection = new Socket(InetAddress.getByName("127.0.0.1"),30001);
	if(connection.isConnected()){
		setName("Connected to 127.0.0.1");
		updatePopupMessageAndPreview1();
	}else{
		setName("Connection Fail!!!!!");
		updatePopupMessageAndPreview1();
	}
}

private void setupStreams() throws IOException, InterruptedException{
	setName("Set up stream......");
	updatePopupMessageAndPreview2();
	output = new PrintWriter(connection.getOutputStream(),true);
	if(output.checkError()){
		setName("Stream setup FAIL!!!!");
		updatePopupMessageAndPreview3();
	}
	else{
		setName("Stream setup done!!!!");
		updatePopupMessageAndPreview3();
	}
}

private void sendScript(String s) throws InterruptedException{
	setName("Sending Script.....");
	updatePopupMessageAndPreview4();
	output.write(s);
	setName("Done");
	updatePopupMessageAndPreview5();
}

private void closeSocket() throws InterruptedException{
	setName("Closing socket......");
	updatePopupMessageAndPreview6();
	try{
		connection.close();
		output.close();
	}catch(IOException ioException){
		ioException.printStackTrace();
	}
	setName("Socket closed!!!!");
	updatePopupMessageAndPreview7();
}

@Input(id = "yourname")
public void onInput(InputEvent event) {
	if (event.getEventType() == InputEvent.EventType.ON_CHANGE) {
		setName(nameTextField.getText());
		updatePopupMessageAndPreview();
	}
}

@Override
public void openView() {
		setName(nameTextField.getText());
		updatePopupMessageAndPreview();
	}

@Override
public void closeView() {
}

@Override
public String getTitle() {
	return "HelloWorld: " + (model.isSet(NAME) ? getName() : "");
}

@Override
public boolean isDefined() {
	return getInstallation().isDefined() && !getName().isEmpty();
}

@Override
public void generateScript(ScriptWriter writer) {
	// Directly generate this Program Node's popup message + access the popup title through a global variable
	writer.appendLine("popup(\"" + cachedPopupMessage + "\", hello_world_popup_title, False, False, blocking=True)");
	writer.writeChildren();
}

private void updatePopupMessageAndPreview() {
	cachedPopupMessage = getName();
	messagePreviewLabel.setText(cachedPopupMessage);

	titlePreviewLabel.setText(getInstallation().isDefined() ? getInstallation().getPopupTitle() : "No title set");
}
private void updatePopupMessageAndPreview1() {
	cachedPopupMessage1 = getName();
	messagePreviewLabel1.setText(cachedPopupMessage1);

	titlePreviewLabel.setText(getInstallation().isDefined() ? getInstallation().getPopupTitle() : "No title set");
}
private void updatePopupMessageAndPreview2() {
	cachedPopupMessage2 = getName();
	messagePreviewLabel2.setText(cachedPopupMessage2);

	titlePreviewLabel.setText(getInstallation().isDefined() ? getInstallation().getPopupTitle() : "No title set");
}
private void updatePopupMessageAndPreview3() {
	cachedPopupMessage3 = getName();
	messagePreviewLabel3.setText(cachedPopupMessage3);

	titlePreviewLabel.setText(getInstallation().isDefined() ? getInstallation().getPopupTitle() : "No title set");
}
private void updatePopupMessageAndPreview4() {
	cachedPopupMessage4 = getName();
	messagePreviewLabel4.setText(cachedPopupMessage4);

	titlePreviewLabel.setText(getInstallation().isDefined() ? getInstallation().getPopupTitle() : "No title set");
}
private void updatePopupMessageAndPreview5() {
	cachedPopupMessage5 = getName();
	messagePreviewLabel5.setText(cachedPopupMessage5);

	titlePreviewLabel.setText(getInstallation().isDefined() ? getInstallation().getPopupTitle() : "No title set");
}
private void updatePopupMessageAndPreview6() {
	cachedPopupMessage6 = getName();
	messagePreviewLabel6.setText(cachedPopupMessage6);

	titlePreviewLabel.setText(getInstallation().isDefined() ? getInstallation().getPopupTitle() : "No title set");
}
private void updatePopupMessageAndPreview7() {
	cachedPopupMessage7 = getName();
	messagePreviewLabel7.setText(cachedPopupMessage7);

	titlePreviewLabel.setText(getInstallation().isDefined() ? getInstallation().getPopupTitle() : "No title set");
}

private String getName() {
	return model.get(NAME, "");
}

private void setName(String name) {
	if ("".equals(name)){
		model.remove(NAME);
	}else{
		model.set(NAME, name);
	}
}

private HelloWorldInstallationNodeContribution getInstallation() {
	return api.getInstallationNode(HelloWorldInstallationNodeContribution.class);
}

}

helloworld-1.0-SNAPSHOT-sources.tar.gz (6.3 KB)

also if we want to receive the return value from URScript and assign it to variable .eg(get_digital_in(0)), how should we do it? is echo a correct approach?

Thanks