NetBurner 3.5.0
PDF Version |
|
The NetBurner API provides two mechanisms to implement UDP: sockets and a C++ class. The choice of which to use is Dependent of which method you find most comfortable using. There is not a performance difference.
To receive UDP Packets:
RegisterUDPFifo()
to listen for and store incoming packets. If listening on more than one port number, a separate OS_FIFO can be used for each port, or one OS_FIFO can be used to listen on multiple ports by calling RegisterUDPFifo()
for each port number and specifying the same OS_FIFO.UDPPacket upkt(&fifo, timeout)
, which will block until a packet is received, then accept and store the packet.Validate()
member function to verify the packetGetDataBuffer()
member function to obtain the data in the packet To send a UDP packet:
Send()
member function to send the packet
In the while loop of UserMain()
you can see that a UDPPacket object named "pkt" is created. Member functions are then called to specify the source port number, destination port number, add the message data, add a null string terminator, and finally to send the packet. In practice it is a good idea to choose random source port numbers.
UserMain()
creates a task named UdpReceiveTask()
. The task declares an OS_FIFO to use to store incoming packets. Note that it is static so the FIFO is located in global variable space. A UDPPacket object constructor is then called for upkt. It will block until a packet is received. When one does arrive it is verified with the Validate()
member function. If it is a valid packet the ShowData()
utility function is used to display the data in hex format to the debug serial port.