Receiving responses to ogscript.sendUDPAsBytes

Hi,

I’m sending commands to a device using ogscript.sendUDPAsBytes. The device responds via UDP to the port that is specified as the source port in the initial command. Unfortunately Dashboard (running in Windows) appears to send a random source port in the UDP so I can’t setup a listener to receive the response.

Is there a way to receive a response to an ogscript.sendUDPAsBytes command?

Hi Martin.

At present, there is no mechanism to receive a response to a UDP message sent with ogscript.sendUDPAsBytes. We do have mechanisms for receiving responses for TCP messages but not UDP.

A UDP listener is able to respond to whoever sends it a message but does not have a mechanism to initiate a conversation.

For the moment, I can add this to our feature request database and let you know when such a thing is available.

Sorry!

"‹James

#DashBoard

Terribly sorry - it seems that I got this one incorrect.

You CAN initiate a message through a UDP listener. You can use ogscript.getListenerById(“ID_YOU_GAVE_THE_LISTENER”); to get the listener object and have access to:
listener.sendUDPAsBytes(HOST, PORT, BYTES_AS_STRING)
listener.sendUDPBytes(HOST, PORT, BYTE_ARRAY)
and
listener.sendUDPString(HOST, PORT, STRING)

Here is a relatively simple example panel that runs 2 UDP listeners:
One acts as a server and takes any string it is sent, reverses it, and sends it back to the port
The other acts as the ‘client’ and outputs any response from the server

The button requests the client listener object and sends the string “Hello World” to the server.

if (event.isMessageEvent()) { var myString = event.getBytesAsString() + ""; var response = ""; for (var i = myString.length - 1; i >= 0; i--) { response += myString.charAt(i); }

this.writeString(response, false);

}


if (event.isMessageEvent())
{
ogscript.debug("GOT RESPONSE: " + event.getBytesAsString());
}




var listener = ogscript.getListenerById(“listener-to-send-through”);
listener.sendUDPString(“localhost”, 2345, “Hello World”);

#DashBoard

James, many thanks, I think this is a neat way of solving the problem. I’ll let you know how I get on with implementing this in my project.
#DashBoard

Best of luck - post back if you have additional questions (or if you have results to share).
#DashBoard