TCP echo server for GSwifi see: http://mbed.org/users/gsfan/notebook/gainspan_wifi/

Dependencies:   GSwifi mbed

Files at this revision

API Documentation at this revision

Comitter:
gsfan
Date:
Sat Oct 27 00:40:35 2012 +0000
Parent:
1:fdc165a4df04
Commit message:
1st build

Changed in this revision

GSwifi.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/GSwifi.lib	Wed Aug 22 00:50:30 2012 +0000
+++ b/GSwifi.lib	Sat Oct 27 00:40:35 2012 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/gsfan/code/GSwifi/#3b819ba34c6c
+http://mbed.org/users/gsfan/code/GSwifi/#aea56cce3bf5
--- a/main.cpp	Wed Aug 22 00:50:30 2012 +0000
+++ b/main.cpp	Sat Oct 27 00:40:35 2012 +0000
@@ -1,6 +1,7 @@
 #include "mbed.h"
 #include "GSwifi.h"
 
+#define HOST "test.example.com"
 #define PORT 10080
 
 #define SECURE GSSEC_WPA_PSK
@@ -20,12 +21,13 @@
     led2 = 1;
 
     i = gs.recv(cid, buf, sizeof(buf));
-    gs.send(cid, buf, i);
     pc.printf("recv %d\r\n", i);
 }
 
 int main () {
     IpAddr ipaddr, netmask, gateway, nameserver;
+    Host host;
+    int cid;
 
     led1 = 1;
     pc.baud(115200);
@@ -37,13 +39,19 @@
     gs.getAddress(ipaddr, netmask, gateway, nameserver);
     pc.printf("ip %d.%d.%d.%d\r\n", ipaddr[0], ipaddr[1], ipaddr[2], ipaddr[3]);
 
-    pc.printf("listen\r\n");
-    gs.listen(PORT, GSPROT_TCP, &onGsReceive);
+    pc.printf("connection\r\n");
+    host.setName(HOST);
+    host.setPort(PORT);
+    cid = gs.open(host, GSPROT_TCP, &onGsReceive);
+    if (cid < 0) {
+        return -1;
+    }
 
     for (;;) {
         gs.poll();
 
-        wait_ms(50);
+        gs.send(cid, "Hello", 5);
+        wait_ms(500);
         led1 = !led1;
         led2 = 0;
     }