SimpleSocket 1.0 examples
Dependencies: EthernetNetIf SimpleSocket 1.0 mbed
examples/echoserver.cpp@40:84182fc63956, 2013-02-04 (annotated)
- Committer:
- yamaguch
- Date:
- Mon Feb 04 09:04:25 2013 +0000
- Revision:
- 40:84182fc63956
- Parent:
- echoserver.cpp@39:108499af2b53
changed SimpleSocket libary name to SimpleSocketV1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
yamaguch | 39:108499af2b53 | 1 | #include "EthernetNetIf.h" |
yamaguch | 39:108499af2b53 | 2 | #include "SimpleSocket.h" |
yamaguch | 39:108499af2b53 | 3 | |
yamaguch | 39:108499af2b53 | 4 | void echoserver() { |
yamaguch | 39:108499af2b53 | 5 | EthernetNetIf eth; |
yamaguch | 39:108499af2b53 | 6 | eth.setup(); |
yamaguch | 39:108499af2b53 | 7 | |
yamaguch | 39:108499af2b53 | 8 | ServerSocket server(1234); |
yamaguch | 39:108499af2b53 | 9 | |
yamaguch | 39:108499af2b53 | 10 | while (true) { |
yamaguch | 39:108499af2b53 | 11 | ClientSocket socket = server.accept(); |
yamaguch | 39:108499af2b53 | 12 | if (socket) { |
yamaguch | 39:108499af2b53 | 13 | while (socket) { |
yamaguch | 39:108499af2b53 | 14 | char buf[80]; |
yamaguch | 39:108499af2b53 | 15 | int len = socket.read(buf, sizeof(buf)); |
yamaguch | 39:108499af2b53 | 16 | if (len > 0) |
yamaguch | 39:108499af2b53 | 17 | socket.write(buf, len); |
yamaguch | 39:108499af2b53 | 18 | } |
yamaguch | 39:108499af2b53 | 19 | socket.close(); |
yamaguch | 39:108499af2b53 | 20 | } |
yamaguch | 39:108499af2b53 | 21 | } |
yamaguch | 39:108499af2b53 | 22 | } |