public BlyncTcpServer(TcpServerSettings tcpServerSettings) { _tcpListener = new TcpListener(IPAddress.Any, tcpServerSettings.Port); _connectionTimeoutPeriod = tcpServerSettings.ConnectionTimeoutPeriod > 0 ? tcpServerSettings.ConnectionTimeoutPeriod : 15000; _packetStreamFactory = tcpServerSettings.PacketStreamFactory; }
public TcpServer(IOptionsSnapshot <TcpServerSettings> options, CancellationTokenSource cancellationTokenSource, ILogger <TcpServer> logger, IServiceProvider provider) { _serverConfiguration = options.Value; _cancellationTokenSource = cancellationTokenSource; _logger = logger; _provider = provider; _tcpListener = new TcpListener(IPAddress.Parse(_serverConfiguration.IPAddress), _serverConfiguration.Port); _serverThread = new Thread(async() => await ServerLoop()); }
public void StartStop() { var tcpServerSettings = new TcpServerSettings() { IPAddress = "127.0.0.1", Port = 23000 }; var logger = Mock.Of <ILogger <TcpServer> >(); var token = new CancellationTokenSource(); var optionsMock = new Mock <IOptionsSnapshot <TcpServerSettings> >(); optionsMock.Setup(m => m.Value).Returns(tcpServerSettings); var server = new TcpServer(optionsMock.Object, token, logger, null); var tcpClientConnect = new TcpClient(); var tcpClientDisconnect = new TcpClient(); server.Start(); tcpClientConnect.Connect(tcpServerSettings.IPAddress, tcpServerSettings.Port); Assert.IsTrue(tcpClientConnect.Connected); server.Stop(); Assert.ThrowsException <SocketException>(() => tcpClientDisconnect.Connect(tcpServerSettings.IPAddress, tcpServerSettings.Port)); Assert.IsFalse(tcpClientDisconnect.Connected); }
public TcpServer(TcpServerSettings settings, ILogger logger) : base(settings, logger) { }
protected TcpServerBase(TcpServerSettings settings, ILogger logger) { _settings = settings; Logger = logger; }
public CalcServer(TcpServerSettings settings) { server = new TcpServer(settings); server.ChannelCreated += server_ChannelCreated; server.ErrorOccured += server_ErrorOccured; }