Echo Server based on the legacy EthernetNetIf libraries used for a performance comparison with the new networking libraries

Dependencies:   EthernetNetIf mbed

Fork of EchoServer by ryosuke kojima

Committer:
emilmont
Date:
Wed Aug 01 16:25:14 2012 +0000
Revision:
1:7b4661a721c1
Parent:
0:fcd581e3ad7d
Echo Server based on the legacy EthernetNetIf libraries used for a performance comparison with the new networking libraries

Who changed what in which revision?

UserRevisionLine numberNew contents of line
naegawa 0:fcd581e3ad7d 1 /*
naegawa 0:fcd581e3ad7d 2 * Echo server
naegawa 0:fcd581e3ad7d 3 * Listens on TCP and UDP ports 7 for any incoming connections
naegawa 0:fcd581e3ad7d 4 * Re-transmits any incoming bytes
naegawa 0:fcd581e3ad7d 5 */
naegawa 0:fcd581e3ad7d 6
naegawa 0:fcd581e3ad7d 7 #include "mbed.h"
naegawa 0:fcd581e3ad7d 8 #include "EthernetNetIf.h"
naegawa 0:fcd581e3ad7d 9
naegawa 0:fcd581e3ad7d 10 #include "EchoServer.h"
naegawa 0:fcd581e3ad7d 11
naegawa 0:fcd581e3ad7d 12 // Our Echo server
naegawa 0:fcd581e3ad7d 13 EchoServer server;
naegawa 0:fcd581e3ad7d 14
naegawa 0:fcd581e3ad7d 15 /*
naegawa 0:fcd581e3ad7d 16 Function: main
naegawa 0:fcd581e3ad7d 17
naegawa 0:fcd581e3ad7d 18 Sets up the Ethernet interface using DHCP, reports the assigned
naegawa 0:fcd581e3ad7d 19 IP address via serial, binds the Echo server to port 7 on
naegawa 0:fcd581e3ad7d 20 TCP and UDP and then sits in a loop calling Net::poll() to
naegawa 0:fcd581e3ad7d 21 keep the network stack doing its thing
naegawa 0:fcd581e3ad7d 22 */
naegawa 0:fcd581e3ad7d 23 int main() {
naegawa 0:fcd581e3ad7d 24 printf("\r\nSetting up...\r\n");
naegawa 0:fcd581e3ad7d 25 //use DHCP
naegawa 0:fcd581e3ad7d 26
naegawa 0:fcd581e3ad7d 27 // Our Ethernet interface
naegawa 0:fcd581e3ad7d 28 EthernetNetIf eth;
naegawa 0:fcd581e3ad7d 29 EthernetErr ethErr = eth.setup();
naegawa 0:fcd581e3ad7d 30 if (ethErr) {
naegawa 0:fcd581e3ad7d 31 printf("Error %d in setup.\n", ethErr);
naegawa 0:fcd581e3ad7d 32 return -1;
naegawa 0:fcd581e3ad7d 33 }
naegawa 0:fcd581e3ad7d 34 IpAddr ip = eth.getIp();
naegawa 0:fcd581e3ad7d 35
naegawa 0:fcd581e3ad7d 36 printf("mbed IP Address is %d.%d.%d.%d\r\n", ip[0], ip[1], ip[2], ip[3]);
naegawa 0:fcd581e3ad7d 37
emilmont 1:7b4661a721c1 38 server.bind(7,7);
naegawa 0:fcd581e3ad7d 39
naegawa 0:fcd581e3ad7d 40 printf("Entering while loop Net::poll()ing\r\n");
naegawa 0:fcd581e3ad7d 41 while (1) {
naegawa 0:fcd581e3ad7d 42 Net::poll();
naegawa 0:fcd581e3ad7d 43 }
naegawa 0:fcd581e3ad7d 44 }