Dependencies: EthernetNetIf mbed
main.cpp
- Committer:
- naegawa
- Date:
- 2011-06-13
- Revision:
- 0:fcd581e3ad7d
File content as of revision 0:fcd581e3ad7d:
/* * 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 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"); /* //use DHCP // Our Ethernet interface EthernetNetIf eth; EthernetErr ethErr = eth.setup(); if (ethErr) { printf("Error %d in setup.\n", ethErr); return -1; } IpAddr ip = eth.getIp(); */ IpAddr ip(192,168,0,100);// = eth.getIp(); EthernetNetIf eth(ip,IpAddr(255,255,255,0),IpAddr(192,168,0,1),IpAddr(192,168,0,1)); EthernetErr ethErr = eth.setup(); if (ethErr) { printf("Error %d in setup.\n", ethErr); return -1; } printf("mbed IP Address is %d.%d.%d.%d\r\n", ip[0], ip[1], ip[2], ip[3]); server.bind(777,666); printf("Entering while loop Net::poll()ing\r\n"); while (1) { Net::poll(); } }