An Echo server as described in RFC862. Written as a learning exercise for using Donatien's network stack. Hopefully of some use to others to get started with socket programming.
main.cpp
- Committer:
- darran
- Date:
- 2010-06-12
- Revision:
- 0:c4e397ba6a9d
File content as of revision 0:c4e397ba6a9d:
/* * Echo server * Listens on TCP and UDP ports 7 for any incoming connections * Re-transmits any incoming bytes */ #include "mbed.h" #include "EthernetNetIf.h" #include "EchoServer.h" // Our Ethernet interface EthernetNetIf eth; // Our Echo server EchoServer server; /* Function: main Sets up the Ethernet interface using DHCP, reports the assigned IP address via serial, binds the Echo server to port 7 on TCP and UDP and then sits in a loop calling Net::poll() to keep the network stack doing its thing */ int main() { printf("\r\nSetting up...\r\n"); EthernetErr ethErr = eth.setup(); if (ethErr) { printf("Error %d in setup.\n", ethErr); return -1; } IpAddr ip = eth.getIp(); printf("mbed IP Address is %d.%d.%d.%d\r\n", ip[0], ip[1], ip[2], ip[3]); server.bind(); printf("Entering while loop Net::poll()ing\r\n"); while (1) { Net::poll(); } }