eth
Dependencies: EthernetInterface mbed-rtos mbed
Fork of FRDM_K64F-Ethernet by
main.cpp
- Committer:
- dariusz777
- Date:
- 2015-04-23
- Revision:
- 3:5bb986247f20
- Parent:
- 2:ff5c01165824
- Child:
- 4:edeb4d3d1968
File content as of revision 3:5bb986247f20:
#include "mbed.h" #include "EthernetInterface.h" #define IP "***" #define MASK "***" #define GW "***" #define PORT ** 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'; } } } }