Sidebar

UDP Socket Connection

0 votes
431 views
asked Jul 28, 2018 by (150 points)
Our connections with our clients only allow UDP traffic. I only see posts mentioning TCP in the forum, is UDP supported (even through an extension or customization)? Thank you.

2 Answers

0 votes
 
Best answer

I found a UDP listener and sender example.  It has some specific ATNA Logging details, which would need to be modified for your purposes.  In a source node, use a Script, and set the Custom Script:

var socket;
try {
   // create UDP Listener
   socket = new java.net.DatagramSocket(6701);
   qie.info('socket opened: 6701');
   
   // start reciever thread
   var receiverThread = new java.lang.Thread(new java.lang.Runnable() {
      run: function() {
         com.qvera.qie.persistence.ThreadContext.setUser('sys');
         qie.info('receiver thread started');
         try {
            while (qie.isChannelRunning()) {
               // create 4K buffer
               var buf = new Packages.java.lang.reflect.Array.newInstance(java.lang.Byte.TYPE, 4096);
               // create receive packet
               var packet = new java.net.DatagramPacket(buf, buf.length);
               // receive the data
               socket.receive(packet);
               // extract the data
               var data = new java.lang.String(packet.getData(), 0, packet.getLength(), "UTF-8");
               qie.info('data received: ' + data);
               // add to inbound queue
               var auditMessage = data.substring(data.indexOf('<AuditMessage'));
               qie.addInboundMessage(auditMessage, null);
            }
         } catch (err) {
            qie.info('receiver thread error: ' + err);
         }
         qie.info('receiver thread stopped');
      }
   });
   receiverThread.setDaemon(true);
   receiverThread.start();
   
   // loop until channel is stopped
   while (qie.isChannelRunning()) {
      try {
         java.lang.Thread.sleep(500);
      } catch (err) {
         qie.debug("Early wake-up call received.");
      }
   }
} finally {
   socket.close();
   qie.info('socket closed: 6701');
}
 

In order to send to UDP message, you can use the following script:

var clientSocket = new java.net.DatagramSocket();
var IPAddress = java.net.InetAddress.getByName("destinationHost");
var sendPacket = new java.net.DatagramPacket(message.getBytes(), message.getBytes().length, IPAddress, 6701);
clientSocket.send(sendPacket);
clientSocket.close();
 

It should be noted that UDP does not provide delivery confirmation, and therefore will likely drop packets and neither system will know about it.  UDP should not be used with critical data.

answered Jul 31, 2018 by mike-r-7535 (13,830 points)
0 votes
Currently QIE has no native support for UDP. We may have a third party jar that may enable it. UDP is not reliable and is not recommended.

Please email us @ support@qvera.com to discuss further.
answered Jul 30, 2018 by brandon-w-8204 (33,330 points)
...