wifly tcp echo server example

Dependencies:   WiflyInterface mbed

Revision:
0:0710a5e21ef9
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Dec 20 15:31:13 2012 +0000
@@ -0,0 +1,38 @@
+#include "mbed.h"
+#include "WiflyInterface.h"
+
+#define ECHO_SERVER_PORT   7
+
+/* wifly object where:
+*     - p9 and p10 are for the serial communication
+*     - p25 is for the reset pin
+*     - p26 is for the connection status
+*     - "mbed" is the ssid of the network
+*     - "password" is the password
+*     - WPA is the security
+*/
+WiflyInterface wifly(p9, p10, p25, p26, "mbed", "password", WPA);
+
+int main (void)
+{
+    wifly.init(); // use DHCP
+    while (!wifly.connect()); // join the network
+    printf("IP Address is %s\n\r", wifly.getIPAddress());
+
+    TCPSocketServer server;
+    server.bind(ECHO_SERVER_PORT);
+    server.listen();
+
+    printf("\nWait for new connection...\n");
+    TCPSocketConnection client;
+    server.accept(client);
+
+    char buffer[256];
+    while (true) {
+        int n = client.receive(buffer, sizeof(buffer));
+        if (n <= 0) continue;
+        buffer[n] = 0;
+
+        client.send_all(buffer, n);
+    }
+}
\ No newline at end of file