Ethernet and TCP
Dependencies: EthernetInterface mbed-rtos mbed
Fork of TCPEchoServer by
Revision 9:9224b02b6192, committed 2017-01-24
- Comitter:
- lachu
- Date:
- Tue Jan 24 12:34:59 2017 +0000
- Parent:
- 8:475898cdb7d4
- Commit message:
- SISK
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 475898cdb7d4 -r 9224b02b6192 main.cpp --- a/main.cpp Thu Jan 12 19:11:37 2017 +0000 +++ b/main.cpp Tue Jan 24 12:34:59 2017 +0000 @@ -4,19 +4,14 @@ #define ECHO_SERVER_PORT 7 -DigitalOut led1(LED1); -DigitalOut led2(LED2); -DigitalOut led3(LED3); - int main (void) { - led1 = !led1; - led2 = !led2; - led3 = !led3; EthernetInterface eth; - eth.init(); //Use DHCP + //1)Inicjalizacja interfejsu (DHCP) + eth.connect(); - printf("\nServer IP Address is %s\n", eth.getIPAddress()); + //2) + printf("\nServer IP Address is %s\n", *** ); TCPSocketServer server; server.bind(ECHO_SERVER_PORT); @@ -26,16 +21,14 @@ printf("\nWait for new connection...\n"); TCPSocketConnection client; server.accept(client); - client.set_blocking(false, 15000); // Timeout after (1.5)s + client.set_blocking(false, 20000); // Timeout after 20s printf("Connection from: %s\n", client.get_address()); char buffer[256]; - //std::string myCommand; - //myCommand = buffer; + while (true) { - printf("TEST1\n"); + int n = client.receive(buffer, sizeof(buffer)); - //if (n <= 0) break; printf("Received message from Client :'%s'\n",buffer); @@ -44,52 +37,31 @@ printf("Variable n is: %d\n", n); + //3 if(n>0){ if(strcmp(buffer, "red") == 0){ printf("REDled\n"); - led1.write(0); + //TODO }else if(strcmp(buffer, "green") == 0){ printf("GREENled\n"); - led2.write(0); + //TODO }else if(strcmp(buffer, "blue") == 0){ printf("BLUEled\n"); - led3.write(0); + //TODO }else if(strcmp(buffer, "clear") == 0){ printf("CLEAR\n"); - led1.write(1); - led2.write(1); - led3.write(1); - }else if(strcmp(buffer, "white") == 0){ - printf("WHITE\n"); - led1.write(0); - led2.write(0); - led3.write(0); - }else if(strcmp(buffer, "tred") == 0){ - printf("REDtoggleled\n"); - led1 = !led1; - }else if(strcmp(buffer, "tgreen") == 0){ - printf("GREENtoggleled\n"); - led2 = !led2; - }else if(strcmp(buffer, "tblue") == 0){ - printf("BLUEtoggleled\n"); - led3 = !led3; - }else if(strcmp(buffer, "CLOSE") == 0){ + //TODO + }else if(strcmp(buffer, "close") == 0){ printf("CLOSE\n"); break; } } - //led3.write(1); printf("Received message from Client :'%s'\n",buffer); n=0; - //if (n <= 0) break; + } - printf("TEST2"); client.close(); - led1.write(1); - led2.write(1); - led3.write(1); - printf(" TEST3\n"); } }