Echo Server based on the legacy EthernetNetIf libraries used for a performance comparison with the new networking libraries
Dependencies: EthernetNetIf mbed
Fork of EchoServer by
EchoServer.h@1:7b4661a721c1, 2012-08-01 (annotated)
- Committer:
- emilmont
- Date:
- Wed Aug 01 16:25:14 2012 +0000
- Revision:
- 1:7b4661a721c1
- Parent:
- 0:fcd581e3ad7d
Echo Server based on the legacy EthernetNetIf libraries used for a performance comparison with the new networking libraries
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
naegawa | 0:fcd581e3ad7d | 1 | #ifndef ECHO_SERVER_H |
naegawa | 0:fcd581e3ad7d | 2 | #define ECHO_SERVER_H |
naegawa | 0:fcd581e3ad7d | 3 | |
naegawa | 0:fcd581e3ad7d | 4 | #include "mbed.h" |
naegawa | 0:fcd581e3ad7d | 5 | #include "TCPSocket.h" |
naegawa | 0:fcd581e3ad7d | 6 | #include "UDPSocket.h" |
naegawa | 0:fcd581e3ad7d | 7 | #include "EthernetNetIf.h" |
naegawa | 0:fcd581e3ad7d | 8 | |
naegawa | 0:fcd581e3ad7d | 9 | #include "TCPEchoHandler.h" |
naegawa | 0:fcd581e3ad7d | 10 | #include <netservice.h> |
naegawa | 0:fcd581e3ad7d | 11 | /* |
naegawa | 0:fcd581e3ad7d | 12 | Class: EchoServer |
naegawa | 0:fcd581e3ad7d | 13 | Binds itself to port 7 on TCP and UDP and listens for |
naegawa | 0:fcd581e3ad7d | 14 | incoming connections |
naegawa | 0:fcd581e3ad7d | 15 | */ |
naegawa | 0:fcd581e3ad7d | 16 | class EchoServer { |
naegawa | 0:fcd581e3ad7d | 17 | public: |
naegawa | 0:fcd581e3ad7d | 18 | // Constructor: EchoServer |
naegawa | 0:fcd581e3ad7d | 19 | // Creates the TCP and UDP sockets and wires up |
naegawa | 0:fcd581e3ad7d | 20 | // the event callback methods |
naegawa | 0:fcd581e3ad7d | 21 | EchoServer(); |
naegawa | 0:fcd581e3ad7d | 22 | // Destructor: ~EchoServer |
naegawa | 0:fcd581e3ad7d | 23 | // Deletes the TCP and UDP sockets |
naegawa | 0:fcd581e3ad7d | 24 | ~EchoServer(); |
naegawa | 0:fcd581e3ad7d | 25 | /* |
naegawa | 0:fcd581e3ad7d | 26 | Function: bind |
naegawa | 0:fcd581e3ad7d | 27 | Binds the sockets to the specified ports |
naegawa | 0:fcd581e3ad7d | 28 | Parameters: |
naegawa | 0:fcd581e3ad7d | 29 | tcpPort - The TCP port to bind to (default 7 as per RFC862) |
naegawa | 0:fcd581e3ad7d | 30 | udpPort - The UDP port to bind to (default 7 as per RFC862) |
naegawa | 0:fcd581e3ad7d | 31 | */ |
naegawa | 0:fcd581e3ad7d | 32 | void bind(int tcpPort=7, int udpPort=7); |
naegawa | 0:fcd581e3ad7d | 33 | private: |
naegawa | 0:fcd581e3ad7d | 34 | // Variable: tcpSock |
naegawa | 0:fcd581e3ad7d | 35 | // The TCP server socket |
naegawa | 0:fcd581e3ad7d | 36 | TCPSocket* tcpSock; |
naegawa | 0:fcd581e3ad7d | 37 | // Variable: udpSock |
naegawa | 0:fcd581e3ad7d | 38 | // The UDP socket |
naegawa | 0:fcd581e3ad7d | 39 | UDPSocket* udpSock; |
naegawa | 0:fcd581e3ad7d | 40 | |
naegawa | 0:fcd581e3ad7d | 41 | // Function: onNetTcpSocketEvent |
naegawa | 0:fcd581e3ad7d | 42 | // The callback function called by the network stack whenever an |
naegawa | 0:fcd581e3ad7d | 43 | // event occurs on the TCP socket |
naegawa | 0:fcd581e3ad7d | 44 | // Parameter: e - The event that has occurred |
naegawa | 0:fcd581e3ad7d | 45 | void onNetTcpSocketEvent(TCPSocketEvent e); |
naegawa | 0:fcd581e3ad7d | 46 | // Function: onNetUdpSocketEvent |
naegawa | 0:fcd581e3ad7d | 47 | // The callback function called by the network stack whenever an |
naegawa | 0:fcd581e3ad7d | 48 | // event occurs on the UDP socket |
naegawa | 0:fcd581e3ad7d | 49 | // Parameter: e - The event that has occurred |
naegawa | 0:fcd581e3ad7d | 50 | void onNetUdpSocketEvent(UDPSocketEvent e); |
naegawa | 0:fcd581e3ad7d | 51 | }; |
naegawa | 0:fcd581e3ad7d | 52 | |
naegawa | 0:fcd581e3ad7d | 53 | #endif |