diff options
author | Mattes D <github@xoft.cz> | 2015-01-21 21:12:11 +0100 |
---|---|---|
committer | Mattes D <github@xoft.cz> | 2015-01-22 20:13:05 +0100 |
commit | 5b4c5cf2befebb78ff2b16955c244e79841648a7 (patch) | |
tree | fd634bd69b029b1b4f4850dd48408997e5b6fbfa /tests/Network | |
parent | cNetwork: Added error message to error callbacks. (diff) | |
download | cuberite-5b4c5cf2befebb78ff2b16955c244e79841648a7.tar cuberite-5b4c5cf2befebb78ff2b16955c244e79841648a7.tar.gz cuberite-5b4c5cf2befebb78ff2b16955c244e79841648a7.tar.bz2 cuberite-5b4c5cf2befebb78ff2b16955c244e79841648a7.tar.lz cuberite-5b4c5cf2befebb78ff2b16955c244e79841648a7.tar.xz cuberite-5b4c5cf2befebb78ff2b16955c244e79841648a7.tar.zst cuberite-5b4c5cf2befebb78ff2b16955c244e79841648a7.zip |
Diffstat (limited to '')
-rw-r--r-- | tests/Network/EchoServer.cpp | 50 |
1 files changed, 28 insertions, 22 deletions
diff --git a/tests/Network/EchoServer.cpp b/tests/Network/EchoServer.cpp index 86b517245..061310c82 100644 --- a/tests/Network/EchoServer.cpp +++ b/tests/Network/EchoServer.cpp @@ -12,27 +12,6 @@ -class cEchoServerCallbacks: - public cNetwork::cListenCallbacks -{ - virtual void OnAccepted(cTCPLink & a_Link) override - { - LOGD("New client accepted (%s:%d), sending welcome message.", a_Link.GetRemoteIP().c_str(), a_Link.GetRemotePort()); - // Send a welcome message to each connecting client: - a_Link.Send("Welcome to the simple echo server.\r\n"); - LOGD("Welcome message queued."); - } - - virtual void OnError(int a_ErrorCode, const AString & a_ErrorMsg) override - { - LOGWARNING("An error occured while listening for connections: %d (%s).", a_ErrorCode, a_ErrorMsg.c_str()); - } -}; - - - - - /** cTCPLink callbacks that echo everything they receive back to the remote peer. */ class cEchoLinkCallbacks: public cTCPLink::cCallbacks @@ -70,10 +49,37 @@ class cEchoLinkCallbacks: +class cEchoServerCallbacks: + public cNetwork::cListenCallbacks +{ + virtual cTCPLink::cCallbacksPtr OnIncomingConnection(const AString & a_RemoteIPAddress, UInt16 a_RemotePort) + { + LOGD("New incoming connection(%s:%d).", a_RemoteIPAddress.c_str(), a_RemotePort); + return std::make_shared<cEchoLinkCallbacks>(); + } + + virtual void OnAccepted(cTCPLink & a_Link) override + { + LOGD("New client accepted (%s:%d), sending welcome message.", a_Link.GetRemoteIP().c_str(), a_Link.GetRemotePort()); + // Send a welcome message to each connecting client: + a_Link.Send("Welcome to the simple echo server.\r\n"); + LOGD("Welcome message queued."); + } + + virtual void OnError(int a_ErrorCode, const AString & a_ErrorMsg) override + { + LOGWARNING("An error occured while listening for connections: %d (%s).", a_ErrorCode, a_ErrorMsg.c_str()); + } +}; + + + + + int main() { LOGD("EchoServer: starting up"); - cServerHandlePtr Server = cNetwork::Listen(9876, std::make_shared<cEchoServerCallbacks>(), std::make_shared<cEchoLinkCallbacks>()); + cServerHandlePtr Server = cNetwork::Listen(9876, std::make_shared<cEchoServerCallbacks>()); if (!Server->IsListening()) { LOGWARNING("Cannot listen on port 9876"); |