summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--tests/Network/EchoServer.cpp50
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");