Exemplo n.º 1
0
        public virtual async ValueTask BindAsync(EndPoint endpoint, CancellationToken cancellationToken = default)
        {
            if (endpoint is IPEndPoint ipEndpoint)
            {
                _ipEndpoint = ipEndpoint;
            }
            else
            {
                throw new NotSupportedException("Only IPEndPoint are currently supported by inline sockets.");
            }

            _logger.BindListenSocket(_ipEndpoint);

            _listener = _networkProvider.CreateListener(new NetworkListenerSettings
            {
                IPEndPoint          = _ipEndpoint,
                AllowNatTraversal   = _options.AllowNatTraversal,
                ExclusiveAddressUse = _options.ExclusiveAddressUse,
                ListenerBacklog     = _options.ListenBacklog,
                NoDelay             = _options.NoDelay,
            });

            // the only way to cancel a call to accept a socket is to stop the listener.
            // this is okay, because this call is cancelled only when the listener is about to be
            // unbound and disposed anyway.
            _listenerCancellationCallback = _listener.Stop;

            _listener.Start();
        }
Exemplo n.º 2
0
        public void Start()
        {
            listener.Start();
            logger.Info("ChannelListener accepting connections on port " + Port);

            running        = true;
            listenerThread = new Thread(Run)
            {
                IsBackground = false, Name = "ChannelListener", Priority = ThreadPriority.AboveNormal
            };
            listenerThread.Start();
        }
Exemplo n.º 3
0
 /// <summary>
 /// Start the network service
 /// </summary>
 public void Start()
 {
     if (Interlocked.CompareExchange(ref _state,
                                     (int)ServiceState.RunPending, (int)ServiceState.Stopped) ==
         (int)ServiceState.Stopped)
     {
         try
         {
             _listener.Start();
             _state = (int)ServiceState.Running;
         }
         catch (Exception ex)
         {
             _state = (int)ServiceState.Stopped;
             throw new NetServiceException(CANAPE.Net.Properties.Resources.NetworkServiceBase_CouldNotStartService, ex);
         }
     }
 }
Exemplo n.º 4
0
        public virtual async ValueTask BindAsync(EndPoint endpoint, CancellationToken cancellationToken = default)
        {
            _endpoint = endpoint;
            _logger.BindListenSocket(_endpoint);

            _listener = _networkProvider.CreateListener(new NetworkListenerSettings
            {
                EndPoint            = _endpoint,
                AllowNatTraversal   = _options.AllowNatTraversal,
                ExclusiveAddressUse = _options.ExclusiveAddressUse,
                ListenerBacklog     = _options.ListenBacklog,
                NoDelay             = _options.NoDelay,
            });

            // the only way to cancel a call to accept a socket is to stop the listener.
            // this is okay, because this call is cancelled only when the listener is about to be
            // unbound and disposed anyway.
            _listenerCancellationCallback = _listener.Stop;

            _listener.Start();
        }
Exemplo n.º 5
0
        private void ServerMain()
        {
            listener.Start();

            while (!IsStopped)
            {
                try
                {
                    INetworkTransport client = listener.AcceptClient();

                    if (client != null)
                    {
                        ClientConnection channel = ClientConnection.CreateClientConnection(
                            new ProtoBuffEnvelope(registry),
                            client);

                        channel.ClientId = Guid.NewGuid();

                        Logger.Info("New connection from : " + client.RemoteEndPoint);

                        lock (clientSync)
                        {
                            _connectionList.Add(channel.ClientId, channel);
                        }

                        OnClientConnected(channel.ClientId, channel, client.RemoteEndPoint.ToString());

                        channel.ClientClosed    += OnClientDisconnected;
                        channel.MessageReceived += OnMessageReceived;
                    }
                }
                catch (SocketException)
                {
                    // This is here because AcceptTcpClient throws an exception when we tell it
                    // stop listening.
                    Logger.Debug("SocketServer shutdown.  No longer accepting connections");
                }
            }
        }
Exemplo n.º 6
0
 /// <summary>
 /// Start the listener
 /// </summary>
 public void Start()
 {
     _left.Start();
     _right.Start();
 }