Example #1
0
 public BlyncTcpServer(TcpServerSettings tcpServerSettings)
 {
     _tcpListener             = new TcpListener(IPAddress.Any, tcpServerSettings.Port);
     _connectionTimeoutPeriod = tcpServerSettings.ConnectionTimeoutPeriod > 0
         ? tcpServerSettings.ConnectionTimeoutPeriod
         : 15000;
     _packetStreamFactory = tcpServerSettings.PacketStreamFactory;
 }
Example #2
0
 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());
 }
Example #3
0
        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)
 {
 }
Example #5
0
 protected TcpServerBase(TcpServerSettings settings, ILogger logger)
 {
     _settings = settings;
     Logger    = logger;
 }
Example #6
0
 public CalcServer(TcpServerSettings settings)
 {
     server = new TcpServer(settings);
     server.ChannelCreated += server_ChannelCreated;
     server.ErrorOccured   += server_ErrorOccured;
 }