eth
Dependencies: EthernetInterface mbed-rtos mbed
Fork of FRDM_K64F-Ethernet by
main.cpp
- Committer:
- dariusz777
- Date:
- 2015-04-23
- Revision:
- 2:ff5c01165824
- Parent:
- 1:52ba06578336
- Child:
- 3:5bb986247f20
File content as of revision 2:ff5c01165824:
#include "mbed.h" #include "EthernetInterface.h" #define IP "192.168.0.52" #define MASK "255.255.255.0" #define GW "0.0.0.0" #define PORT 80 void getsth(char a, EthernetInterface e, TCPSocketConnection cli); int main (void){ EthernetInterface eth; eth.init(IP, MASK, GW); //Assign a device ip, mask and gateway // eth.init(); eth.connect(); printf("IP Address is %s\n", eth.getIPAddress()); //"192.168.0.52" TCPSocketServer server; server.bind(PORT); server.listen(); while (true) { printf("\nWait for new connection...\n"); TCPSocketConnection client; server.accept(client); client.set_blocking(false, 1500); // Timeout after (1.5)s printf("Connection from: %s\n", client.get_address()); char buffer[256]; while (true) { int n = client.receive(buffer, sizeof(buffer)); if(n>0) { char a = buffer[0]; if(a == '1') { client.send_all(eth.getIPAddress(),16); } else if(a == '2') { client.send_all(eth.getGateway(),16); } else if(a == '3') { client.send_all(eth.getMACAddress(),17); } else if(a == '4') { client.send_all(eth.getNetworkMask(),16); }else if(a == 'c'){ client.close(); } client.send_all("\n",2); n=0; a='0'; } } } }