Facility Control

 View Only
  • 1.  Receiving responses to ogscript.sendUDPAsBytes

    Posted 02-08-2017 12:41
    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?


  • 2.  RE: Receiving responses to ogscript.sendUDPAsBytes

    Posted 02-13-2017 15:41
    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


  • 3.  RE: Receiving responses to ogscript.sendUDPAsBytes

    Posted 02-22-2017 19:24

    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.

    <abs contexttype="opengear" style="">
       <meta>
          <listener autostart="true" listenport="2345" maxlength="1024" udp="true">
             <task tasktype="ogscript">if (event.isMessageEvent())
    {
       var myString = event.getBytesAsString() + "";
       var response = "";
       for (var i = myString.length - 1; i &gt;= 0; i--)
       {
          response += myString.charAt(i);
       }
    
       this.writeString(response, false);
       
    }</task>
          </listener>
          <listener autostart="true" id="listener-to-send-through" listenport="1234" maxlength="1024" udp="true">
             <task tasktype="ogscript">if (event.isMessageEvent())
    {
       ogscript.debug("GOT RESPONSE: " + event.getBytesAsString());
    }
    </task>
          </listener>
       </meta>
       <button buttontype="push" height="148" left="21" top="18" width="219">
          <task tasktype="ogscript">var listener = ogscript.getListenerById("listener-to-send-through");
    listener.sendUDPString("localhost", 2345, "Hello World");</task>
       </button>
    </abs>

    #DashBoard


  • 4.  RE: Receiving responses to ogscript.sendUDPAsBytes

    Posted 02-25-2017 12:21
    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


  • 5.  RE: Receiving responses to ogscript.sendUDPAsBytes

    Posted 02-27-2017 16:49
    Best of luck - post back if you have additional questions (or if you have results to share).
    #DashBoard