public TcpSocketSaeaSession( TcpSocketSaeaServerConfiguration configuration, IBufferManager bufferManager, SaeaPool saeaPool, ITcpSocketSaeaServerMessageDispatcher dispatcher, TcpSocketSaeaServer server) { if (configuration == null) throw new ArgumentNullException("configuration"); if (bufferManager == null) throw new ArgumentNullException("bufferManager"); if (saeaPool == null) throw new ArgumentNullException("saeaPool"); if (dispatcher == null) throw new ArgumentNullException("dispatcher"); if (server == null) throw new ArgumentNullException("server"); _configuration = configuration; _bufferManager = bufferManager; _saeaPool = saeaPool; _dispatcher = dispatcher; _server = server; _receiveBuffer = _bufferManager.BorrowBuffer(); _receiveBufferOffset = 0; }
public async Task StartAsync(EndPoint endPoint) { var config = new TcpSocketSaeaServerConfiguration(); _server = new TcpSocketSaeaServer((IPEndPoint)endPoint, new SimpleMessageDispatcher((session, message) => { var sender = new SimpleServerMessageSender(_transportMessageEncoder, session, _logger); OnReceived(sender, message); }, _transportMessageDecoder, _logger), config); _server.Listen(); #if NET45 || NET451 await Task.FromResult(1); #else await Task.CompletedTask; #endif }
public async Task StartAsync(EndPoint endPoint) { _server = new TcpSocketSaeaServer((IPEndPoint)endPoint, async (session, data, offset, count) => { if (_logger.IsEnabled(LogLevel.Information)) _logger.LogInformation("接收到数据包。"); var message = _transportMessageDecoder.Decode(data.Skip(offset).Take(count).ToArray()); if (_logger.IsEnabled(LogLevel.Information)) _logger.LogInformation("接收到消息:" + message.Id); var sender = new SimpleServerMessageSender(_transportMessageEncoder, session, _logger); await OnReceived(sender, message); }); _server.Listen(); #if NET await Task.FromResult(1); #else await Task.CompletedTask; #endif }
public TcpSocketSaeaSession( TcpSocketSaeaServerConfiguration configuration, IBufferManager bufferManager, SaeaPool saeaPool, ITcpSocketSaeaServerMessageDispatcher dispatcher, TcpSocketSaeaServer server) { if (configuration == null) { throw new ArgumentNullException("configuration"); } if (bufferManager == null) { throw new ArgumentNullException("bufferManager"); } if (saeaPool == null) { throw new ArgumentNullException("saeaPool"); } if (dispatcher == null) { throw new ArgumentNullException("dispatcher"); } if (server == null) { throw new ArgumentNullException("server"); } _configuration = configuration; _bufferManager = bufferManager; _saeaPool = saeaPool; _dispatcher = dispatcher; _server = server; _receiveBuffer = _bufferManager.BorrowBuffer(); _receiveBufferOffset = 0; }