The following commands can be used to send and receive data over a UDP Socket connection.
NOTE: Because of the nature of UDP/IP, there may only be one script listening to a port on a given IP address. But another script may use that same port on a different IP address (NIC). The expected behavior of UDP-enabled remote devices is to send any responses back to the originating UDP port. The port you specify in the Send() method is not necessarily the one you assign with the Open() method (although they frequently match). Assuming you had many identical devices to control (via the same or separate scripts) that all used the same UDP port number for their remote interfaces, you could have many scripts, each controlling another device on the same remote UDP port. However, on the Q-SYS end, if you expect to also handle UDP responses, you need to be careful to choose unique UDP ports for the Open() method to ensure incoming packets go to the correct script.
Unfortunately, some remote interfaces (that will remain nameless) always send UDP responses to the same UDP port, regardless of the originating port on the opposite end (Q-SYS in this case). In those rare, joyous cases, you have no alternative but to write a single script to receive all responses from all devices and then farm them out to other scripts for final processing, once a determination has been made where the packet originated. This determination is typically done by parsing some type of ID from the received packet. At this point this receiver script would have to send the data to a script associated with the specific instance of remote product. Thankfully, this is a rare circumstance, but one which has caused many programmers countless hours of frustration.
One exception to this is when receiving multicast UDP packets. Those are sent to the same port on every NIC on a Layer 2 network, unless using IGMP Snooping or similar multicast filtering scheme. The Multicast Receive example below allows you to see Q-SYS Discovery Protocol (QDP) packets on your network.
UdpSocket Properties |
||
---|---|---|
Name |
Notes |
Description |
EventHandler |
Signature of function is 'function(socket, data)'
data is a table consisting of the following:
|
Function to call when UDP packet is received. |
Methods | ||
---|---|---|
Names | Arguments | Description |
None |
Creates a UDP Socket instance. |
|
( ip, port ) |
Opens the UDP 'listener.' Optionally bind to local IP and Port. |
|
None |
Closes the UDP socket |
|
( ip_address, port, data ) |
Sends data to ip_address:port. |
|
( address, <ip>) |
Joins a specific multicast 'address', optionally binding to a local 'ip'. |
-- receiving multicast -- (Port 2468 is the port for the Q-SYS Core's IO device queries sent every two seconds) udp = UdpSocket.New() --Create new UDP object
udp.EventHandler = function(udp, packet) print( packet.Address, packet.Port, packet.Data ) end
udp:Open( "192.168.1.100", 2468 ) -- IP address is optional udp:JoinMulticast("224.0.23.175") -- Sends a multicast join report for the multicast address |
local udp = UdpSocket.New()
udp:Open() udp:Send( "224.0.23.175", 2467, "<QDP><query_ref>device.ioframe.*</query_ref></QDP>" ) |
© 2009 - 2016 QSC, LLC. All rights reserved. QSC and the QSC logo are trademarks of QSC, LLC in the U.S. Patent and Trademark office and other countries. All other trademarks are the property of their respective owners.
http://patents.qsc.com.