public TcpSocketRioServer(IPEndPoint listenedEndPoint, ITcpSocketRioServerMessageDispatcher dispatcher, TcpSocketRioServerConfiguration configuration = null) { if (listenedEndPoint == null) { throw new ArgumentNullException("listenedEndPoint"); } if (dispatcher == null) { throw new ArgumentNullException("dispatcher"); } this.ListenedEndPoint = listenedEndPoint; _dispatcher = dispatcher; _configuration = configuration ?? new TcpSocketRioServerConfiguration(); if (_configuration.BufferManager == null) { throw new InvalidProgramException("The buffer manager in configuration cannot be null."); } if (_configuration.FrameBuilder == null) { throw new InvalidProgramException("The frame handler in configuration cannot be null."); } Initialize(); }
public TcpSocketRioSession( TcpSocketRioServerConfiguration configuration, IBufferManager bufferManager, RioConnectionOrientedSocket socket, ITcpSocketRioServerMessageDispatcher dispatcher, TcpSocketRioServer server) { if (configuration == null) throw new ArgumentNullException("configuration"); if (bufferManager == null) throw new ArgumentNullException("bufferManager"); if (socket == null) throw new ArgumentNullException("socket"); if (dispatcher == null) throw new ArgumentNullException("dispatcher"); if (server == null) throw new ArgumentNullException("server"); _configuration = configuration; _bufferManager = bufferManager; _socket = socket; _dispatcher = dispatcher; _server = server; _sessionKey = Guid.NewGuid().ToString(); this.StartTime = DateTime.UtcNow; _receiveBuffer = _bufferManager.BorrowBuffer(); _sessionBuffer = _bufferManager.BorrowBuffer(); _sessionBufferCount = 0; _stream = new RioStream(_socket); }
public TcpSocketRioServer( IPAddress listenedAddress, int listenedPort, Func <TcpSocketRioSession, byte[], int, int, Task> onSessionDataReceived = null, Func <TcpSocketRioSession, Task> onSessionStarted = null, Func <TcpSocketRioSession, Task> onSessionClosed = null, TcpSocketRioServerConfiguration configuration = null) : this(new IPEndPoint(listenedAddress, listenedPort), onSessionDataReceived, onSessionStarted, onSessionClosed, configuration) { }
public TcpSocketRioServer( IPAddress listenedAddress, int listenedPort, Func<TcpSocketRioSession, byte[], int, int, Task> onSessionDataReceived = null, Func<TcpSocketRioSession, Task> onSessionStarted = null, Func<TcpSocketRioSession, Task> onSessionClosed = null, TcpSocketRioServerConfiguration configuration = null) : this(new IPEndPoint(listenedAddress, listenedPort), onSessionDataReceived, onSessionStarted, onSessionClosed, configuration) { }
public TcpSocketRioServer( IPEndPoint listenedEndPoint, Func <TcpSocketRioSession, byte[], int, int, Task> onSessionDataReceived = null, Func <TcpSocketRioSession, Task> onSessionStarted = null, Func <TcpSocketRioSession, Task> onSessionClosed = null, TcpSocketRioServerConfiguration configuration = null) : this(listenedEndPoint, new InternalTcpSocketRioServerMessageDispatcherImplementation(onSessionDataReceived, onSessionStarted, onSessionClosed), configuration) { }
public TcpSocketRioServer( IPEndPoint listenedEndPoint, Func <TcpSocketRioSession, byte[], int, int, Task> onSessionDataReceived = null, Func <TcpSocketRioSession, Task> onSessionStarted = null, Func <TcpSocketRioSession, Task> onSessionClosed = null, TcpSocketRioServerConfiguration configuration = null) : this(listenedEndPoint, new DefaultTcpSocketRioServerEventDispatcher(onSessionDataReceived, onSessionStarted, onSessionClosed), configuration) { }
public TcpSocketRioServer(IPEndPoint listenedEndPoint, ITcpSocketRioServerMessageDispatcher dispatcher, TcpSocketRioServerConfiguration configuration = null) { if (listenedEndPoint == null) throw new ArgumentNullException("listenedEndPoint"); if (dispatcher == null) throw new ArgumentNullException("dispatcher"); this.ListenedEndPoint = listenedEndPoint; _dispatcher = dispatcher; _configuration = configuration ?? new TcpSocketRioServerConfiguration(); if (_configuration.FrameBuilder == null) throw new InvalidProgramException("The frame handler in configuration cannot be null."); Initialize(); }
public TcpSocketRioSession( TcpSocketRioServerConfiguration configuration, ISegmentBufferManager bufferManager, RioSocket socket, ITcpSocketRioServerMessageDispatcher dispatcher, TcpSocketRioServer server) { if (configuration == null) { throw new ArgumentNullException("configuration"); } if (bufferManager == null) { throw new ArgumentNullException("bufferManager"); } if (socket == null) { throw new ArgumentNullException("socket"); } if (dispatcher == null) { throw new ArgumentNullException("dispatcher"); } if (server == null) { throw new ArgumentNullException("server"); } _configuration = configuration; _bufferManager = bufferManager; _socket = socket; _dispatcher = dispatcher; _server = server; _sessionKey = Guid.NewGuid().ToString(); this.StartTime = DateTime.UtcNow; if (_receiveBuffer == default(ArraySegment <byte>)) { _receiveBuffer = _bufferManager.BorrowBuffer(); } _receiveBufferOffset = 0; _stream = new RioStream(_socket); }
public TcpSocketRioSession( TcpSocketRioServerConfiguration configuration, IBufferManager bufferManager, RioConnectionOrientedSocket socket, ITcpSocketRioServerMessageDispatcher dispatcher, TcpSocketRioServer server) { if (configuration == null) { throw new ArgumentNullException("configuration"); } if (bufferManager == null) { throw new ArgumentNullException("bufferManager"); } if (socket == null) { throw new ArgumentNullException("socket"); } if (dispatcher == null) { throw new ArgumentNullException("dispatcher"); } if (server == null) { throw new ArgumentNullException("server"); } _configuration = configuration; _bufferManager = bufferManager; _socket = socket; _dispatcher = dispatcher; _server = server; _sessionKey = Guid.NewGuid().ToString(); this.StartTime = DateTime.UtcNow; _receiveBuffer = _bufferManager.BorrowBuffer(); _sessionBuffer = _bufferManager.BorrowBuffer(); _sessionBufferCount = 0; _stream = new RioStream(_socket); }
static void Main(string[] args) { NLogLogger.Use(); try { var config = new TcpSocketRioServerConfiguration(); _server = new TcpSocketRioServer(22222, new SimpleMessageDispatcher(), config); _server.Listen(); Console.WriteLine("TCP server has been started on [{0}].", _server.ListenedEndPoint); Console.WriteLine("Type something to send to clients..."); while (true) { try { string text = Console.ReadLine(); if (text == "quit") break; Task.Run(async () => { await _server.BroadcastAsync(Encoding.UTF8.GetBytes(text)); Console.WriteLine("Server [{0}] broadcasts text -> [{1}].", _server.ListenedEndPoint, text); }); } catch (Exception ex) { Console.WriteLine(ex.Message); } } _server.Shutdown(); Console.WriteLine("TCP server has been stopped on [{0}].", _server.ListenedEndPoint); } catch (Exception ex) { Logger.Get<Program>().Error(ex.Message, ex); } Console.ReadKey(); }
public TcpSocketRioServer(IPAddress listenedAddress, int listenedPort, ITcpSocketRioServerMessageDispatcher dispatcher, TcpSocketRioServerConfiguration configuration = null) : this(new IPEndPoint(listenedAddress, listenedPort), dispatcher, configuration) { }
public TcpSocketRioServer(int listenedPort, ITcpSocketRioServerMessageDispatcher dispatcher, TcpSocketRioServerConfiguration configuration = null) : this(IPAddress.Any, listenedPort, dispatcher, configuration) { }
public TcpSocketRioServer( IPEndPoint listenedEndPoint, Func<TcpSocketRioSession, byte[], int, int, Task> onSessionDataReceived = null, Func<TcpSocketRioSession, Task> onSessionStarted = null, Func<TcpSocketRioSession, Task> onSessionClosed = null, TcpSocketRioServerConfiguration configuration = null) : this(listenedEndPoint, new InternalTcpSocketRioServerMessageDispatcherImplementation(onSessionDataReceived, onSessionStarted, onSessionClosed), configuration) { }
static void Main(string[] args) { NLogLogger.Use(); try { var config = new TcpSocketRioServerConfiguration(); //config.FrameBuilder = new FixedLengthFrameBuilder(20000); //config.FrameBuilder = new RawBufferFrameBuilder(); //config.FrameBuilder = new LineBasedFrameBuilder(); //config.FrameBuilder = new LengthPrefixedFrameBuilder(); //config.FrameBuilder = new LengthFieldBasedFrameBuilder(); _server = new TcpSocketRioServer(22222, new SimpleMessageDispatcher(), config); _server.Listen(); Console.WriteLine("TCP server has been started on [{0}].", _server.ListenedEndPoint); Console.WriteLine("Type something to send to clients..."); while (true) { try { string text = Console.ReadLine(); if (text == "quit") break; Task.Run(async () => { if (text == "many") { text = new string('x', 8192); for (int i = 0; i < 1000000; i++) { await _server.BroadcastAsync(Encoding.UTF8.GetBytes(text)); Console.WriteLine("Server [{0}] broadcasts text -> [{1}].", _server.ListenedEndPoint, text); } } else if (text == "big") { text = new string('x', 1024 * 1024 * 100); await _server.BroadcastAsync(Encoding.UTF8.GetBytes(text)); Console.WriteLine("Server [{0}] broadcasts text -> [{1}].", _server.ListenedEndPoint, text); } else { await _server.BroadcastAsync(Encoding.UTF8.GetBytes(text)); Console.WriteLine("Server [{0}] broadcasts text -> [{1}].", _server.ListenedEndPoint, text); } }); } catch (Exception ex) { Logger.Get<Program>().Error(ex.Message, ex); } } _server.Shutdown(); Console.WriteLine("TCP server has been stopped on [{0}].", _server.ListenedEndPoint); } catch (Exception ex) { Logger.Get<Program>().Error(ex.Message, ex); } Console.ReadKey(); }