Simple code for comunication via TCP between the mbed and PC.

Dependencies:   EthernetInterface SimpleSocket mbed-rtos mbed

Fork of SimpleSocketExamples by Hiroshi Yamaguchi

examples/echoserver.cpp

Committer:
numeral369
Date:
2014-12-17
Revision:
1:016774025718
Parent:
0:6dc3cfd058c6

File content as of revision 1:016774025718:

#include "SimpleSocket.h"

void echoserver()
{
    ServerSocket server(1234);

    printf("server: %s:1234\n", EthernetInterface::getIPAddress());

    while (true) {
        ClientSocket socket = server.accept();

        if (socket) {
            while (socket) {
                char buf[80];
                int len = socket.read(buf, sizeof(buf));
                if (len > 0)
                    socket.write(buf, len);
            }
            socket.close();
        }
        wait(1.0);
    }
}