URCap to Dashboard server commands

Hello,
I have found a solution and I just want to post it here for everyone to know. Below you can find the solution. Maybe not the most elegant.
I just use the code from library which is used to connect to the socket and put it inside the function for when the button is pressed.
I have tested and it works. Maybe it will help someone.
Thank you for your help!

public void sendScriptTest() {

		//String command=new String("play");
		String command ="play";
			
			
			try{
				// Create a new Socket Client
				Socket sc = new Socket("127.0.0.1", 29999);
				if (sc.isConnected()){
					// Create stream for data
					DataOutputStream out;
					out = new DataOutputStream(sc.getOutputStream());
					
					// Send command
					out.write(command.getBytes("US-ASCII"));
					out.flush();

					// Perform housekeeping 
					out.close();
				}
				sc.close();
			} 
			catch (IOException e){
				System.out.println(e);
			}
		}
1 Like