wifly tcp echo server example
Dependencies: WiflyInterface mbed
Revision 0:0710a5e21ef9, committed 2012-12-20
- Comitter:
- samux
- Date:
- Thu Dec 20 15:31:13 2012 +0000
- Commit message:
- wifly tcp echo server example
Changed in this revision
diff -r 000000000000 -r 0710a5e21ef9 WiflyInterface.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/WiflyInterface.lib Thu Dec 20 15:31:13 2012 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/WiflyInterface/#0bcec6272784
diff -r 000000000000 -r 0710a5e21ef9 main.cpp --- /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
diff -r 000000000000 -r 0710a5e21ef9 mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Thu Dec 20 15:31:13 2012 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/63cdd78b2dc1 \ No newline at end of file