// Register and handle the connection private async Task StartHandleConnectionAsync() { m_Server = CreateServer(m_ServerTcp); // start the new connection task var connectionTask = m_Server.Run(); OnServerConnected(m_Server); // catch all errors of HandleConnectionAsync try { await connectionTask; // we may be on another thread after "await" } catch (IOException) { OnServerDisconnected(m_Server); } finally { m_Server = null; m_ServerTcp = null; } }
protected abstract void OnClientDisconnected(RemoteTcpEntity client);
protected abstract void OnServerDisconnected(RemoteTcpEntity client);