/// <summary> /// On session data received event. /// </summary> /// <param name="session">TCP session.</param> /// <param name="data"></param> /// <param name="offset"></param> /// <param name="count"></param> /// <returns> /// Session data received task. /// </returns> public async Task OnSessionDataReceived(AsyncTcpServerSession session, byte[] data, int offset, int count) { if (null != this._on_session_data_received) { await this._on_session_data_received(session, data, offset, count); } }
/// <summary> /// On session closed event. /// </summary> /// <param name="session">TCP session.</param> /// <returns> /// Session closed opertion task. /// </returns> public async Task OnSessionClosed(AsyncTcpServerSession session) { if (null != this._on_session_closed) { await this._on_session_closed(session); } }
public AsyncTcpServerSession GetSession(string sessionKey) { AsyncTcpServerSession session = null; _sessions.TryGetValue(sessionKey, out session); return(session); }
public async Task CloseSession(string sessionKey) { AsyncTcpServerSession session = null; if (_sessions.TryGetValue(sessionKey, out session)) { await session.Close(); // parent server close session by session-key } }
public async Task SendToAsync(AsyncTcpServerSession session, byte[] data, int offset, int count) { AsyncTcpServerSession sessionFound; if (_sessions.TryGetValue(session.SessionKey, out sessionFound)) { await sessionFound.SendAsync(data, offset, count); } else { } }
private async Task Process(TcpClient acceptedTcpClient) { var session = new AsyncTcpServerSession(acceptedTcpClient, _configuration, _configuration.BufferManager, _dispatcher, this); if (_sessions.TryAdd(session.SessionKey, session)) { try { await session.Start(); } catch (TimeoutException ex) { } finally { AsyncTcpServerSession throwAway; if (_sessions.TryRemove(session.SessionKey, out throwAway)) { } } } }
public async Task SendToAsync(AsyncTcpServerSession session, byte[] data) { await SendToAsync(session, data, 0, data.Length); }