<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Recent changes to UDP</title><link>https://sourceforge.net/p/chipkitnetwork/wiki/UDP/</link><description>Recent changes to UDP</description><atom:link href="https://sourceforge.net/p/chipkitnetwork/wiki/UDP/feed" rel="self"/><language>en</language><lastBuildDate>Sat, 07 Jul 2012 14:18:59 -0000</lastBuildDate><atom:link href="https://sourceforge.net/p/chipkitnetwork/wiki/UDP/feed" rel="self" type="application/rss+xml"/><item><title>WikiPage UDP modified by Majenko Technologies</title><link>https://sourceforge.net/p/chipkitnetwork/wiki/UDP/</link><description>&lt;pre&gt;--- v2
+++ v3
@@ -5,6 +5,10 @@
     UDP mySocket(10000);
 
 All packets sent will be from that port number, and packets arriving into that port number will be added to the UDP port queue.
+
+You then need to add the socket to the networking stack:
+
+    Network.addPort(mySocket);
 
 Sending and receiving packets is as simple as:
 
&lt;/pre&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Majenko Technologies</dc:creator><pubDate>Sat, 07 Jul 2012 14:18:59 -0000</pubDate><guid>https://sourceforge.net665dea52ba514621b6de118275c5aa149d1e9b62</guid></item><item><title>WikiPage UDP modified by Majenko Technologies</title><link>https://sourceforge.net/p/chipkitnetwork/wiki/UDP/</link><description>&lt;pre&gt;--- v1
+++ v2
@@ -31,3 +31,9 @@
     port = mySocket.peerPort();
 
 Be sure to do that *before* reading the packet with *recv()* or you will be looking at the next packet in the queue.
+
+To find out if there are any packets available for reading you can use the *available()* method:
+
+    avail = mySocket.available();
+
+That returns the number of packets in the incoming queue, much like the Serial.available() method.  You should check that value *before* doing any reading of the packets.
&lt;/pre&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Majenko Technologies</dc:creator><pubDate>Sat, 07 Jul 2012 14:16:05 -0000</pubDate><guid>https://sourceforge.net36c240b8c42e7843c11c493243789b6236e0b572</guid></item><item><title>WikiPage UDP modified by Majenko Technologies</title><link>https://sourceforge.net/p/chipkitnetwork/wiki/UDP/</link><description>The UDP object is perhaps the most simple of the communication socket objects.

You first create the UDP object itself, specifying the local port number:

    UDP mySocket(10000);

All packets sent will be from that port number, and packets arriving into that port number will be added to the UDP port queue.

Sending and receiving packets is as simple as:

    mySocket.send(ipAddress, remotePort, data, length);

The ipAddress is an unsigned long type and can be created using the quad2ip function.  For example, to send 200 bytes of data to port 20000 on 192.168.0.80 you would use:

    mySocket.send(quad2ip(192,168,0,80), 20000, myData, 200);

Where *myData* is a pointer to the data in *unsigned char* format.

Receiving is done with the .recv() method:

    len = mySocket.recv(data);

The data from the packet is stored in the unsigned char buffer pointer to by *data* and the number of bytes received is returned.

To find out where data is coming from, you can inspect the sender IP and sender port of the next packet in the queue using:

    ip = mySocket.peerAddress();

and

    port = mySocket.peerPort();

Be sure to do that *before* reading the packet with *recv()* or you will be looking at the next packet in the queue.</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Majenko Technologies</dc:creator><pubDate>Sat, 07 Jul 2012 14:14:20 -0000</pubDate><guid>https://sourceforge.netf91daf59af41c2d7419f90513d144f2c3e751e0e</guid></item></channel></rss>