Flex Datagram Server
DatagramServer is small library for Flex+Parsley that allows you to set up and manage a UDP listener in your Air 2.5+ application.
UDP Packets in Flex Air apps
Datagram packets are ideal for gathering data from external devices without having to establish two-way persistent socket connections. Perfect for gathering logs, benchmark data, statistics, …etc.
Note: You can send and receive UDP packets in Air 2.5+, but only on desktop Air apps. MobileDevice, extendedMobileDevice, tv, extendedTV profiles are unsupported.
You can download the DatagramServer swc from github:
Setup
- In your Parsley contextbuilder register DatagramServerContext:
- If you want to edit the datagram host and port from the UI, fastinject DatagramModel, then create a two way binding to .host and .port:
- Start/Stop the Datagram server from any parsley-managed class, eg.::
- To listen to incoming UDP packages, create a parsley messagehandler:
[MessageHandler] public function dataReceived(e:DataReceivedEvent):void { logs.add(e.string); /** * you can also use: * e.ip : returns the IP of the sender * e.data : returns the packet as a bytearray * e.xml : returns the packet as xml */ }
[MessageHandler] public function dataReceived(e:DataReceivedEvent):void { logs.add(e.string); /** * you can also use: * e.ip : returns the IP of the sender * e.data : returns the packet as a bytearray * e.xml : returns the packet as xml */ }
How to test your Datagram Listener
You can use Netcat to send udp packages. On a mac:
Example
Blogroll



