public ClientConnection(MessageEnvelope envelope, INetworkTransport client)
        {
            this.client = client;
            Envelope = envelope;

            ClientId = Guid.NewGuid();
        }
 public virtual void Stop()
 {
     if (transport != null)
     {
         transport.Destroy();
         transport = null;
     }
 }
 public TvDiscovery(IDeviceDiscovery upnpDiscovery, INetworkTransport networkTransport)
 {
     this.transport     = networkTransport;
     this.upnpDiscovery = upnpDiscovery;
     this.upnpDiscovery.DeviceConnected    += new EventHandler <DeviceInfoEventArgs>(this.upnpDiscovery_DeviceConnected);
     this.upnpDiscovery.DeviceDisconnected += new EventHandler <DeviceInfoEventArgs>(this.upnpDiscovery_DeviceDisconnected);
     this.devicePool                = new DevicePool();
     this.devicePool.DeviceAdded   += new EventHandler <DeviceInfoEventArgs>(this.devicePool_DeviceAdded);
     this.devicePool.DeviceRemoved += new EventHandler <DeviceInfoEventArgs>(this.devicePool_DeviceRemoved);
 }
Beispiel #4
0
        internal void StartServer()
        {
            INIT();
            if (m_activeTransport == null)
            {
                m_activeTransport = new BaseServerTransport(m_MessageHandlers);
            }

            m_activeTransport.SetOperational(true);
            m_activeTransport.StartListening();
        }
Beispiel #5
0
        internal void StartClient()
        {
            INIT();

            if (m_activeTransport == null)
            {
                m_activeTransport = new BaseClientTransport(m_MessageHandlers);
            }

            m_activeTransport.SetOperational(true);
            m_activeTransport.StartClient();
        }
Beispiel #6
0
        private async Task DoConnect(TcpClient client, string hostname, bool text, bool tls, bool verify_tls, bool buffered)
        {
            Stream stm;

            _client         = client;
            _client.NoDelay = true;

            if (tls)
            {
                RemoteCertificateValidationCallback validation = verify_tls ?
                                                                 new RemoteCertificateValidationCallback(ValidateRemoteConnection) :
                                                                 new RemoteCertificateValidationCallback(ValidateRemoteConnectionBypass);
                SslStream sslStream = new SslStream(_client.GetStream(), false,
                                                    validation);

                int lastTimeout = sslStream.ReadTimeout;
                sslStream.ReadTimeout = 3000;
                await sslStream.AuthenticateAsClientAsync(hostname);

                Console.WriteLine("TLS Protocol: {0}", SslProtocolToString(sslStream.SslProtocol));
                Console.WriteLine("TLS KeyEx   : {0}", KeyExToString(sslStream.KeyExchangeAlgorithm));
                Console.WriteLine("TLS Cipher:   {0}", sslStream.CipherAlgorithm);
                Console.WriteLine("TLS Hash:     {0}", sslStream.HashAlgorithm);
                Console.WriteLine("Cert Subject: {0}", sslStream.RemoteCertificate.Subject);
                Console.WriteLine("Cert Issuer : {0}", sslStream.RemoteCertificate.Issuer);

                sslStream.ReadTimeout = lastTimeout;

                stm = sslStream;
            }
            else
            {
                stm = _client.GetStream();
            }

            _base_stream = new XorStream(stm);
            if (text)
            {
                NetworkUtils.WriteNetworkOrderInt32(_base_stream, NetworkUtils.TEXT_MAGIC);
                _transport = new TextNetworkTransport(_base_stream);
            }
            else
            {
                NetworkUtils.WriteNetworkOrderInt32(_base_stream, NetworkUtils.BINARY_MAGIC);
                _transport = new BinaryNetworkTransport(_base_stream, buffered);
            }
        }
Beispiel #7
0
    unsafe public NetworkServer(INetworkTransport transport)
    {
        _transport = transport;

        serverInfo = new ServerInfo();
        // Allocate array to hold world snapshots
        m_Snapshots = new WorldSnapshot[NetworkConfig.snapshotDeltaCacheSize];
        for (int i = 0; i < m_Snapshots.Length; ++i)
        {
            m_Snapshots[i]      = new WorldSnapshot();
            m_Snapshots[i].data = (uint *)UnsafeUtility.Malloc(NetworkConfig.maxWorldSnapshotDataSize, UnsafeUtility.AlignOf <UInt32>(), Unity.Collections.Allocator.Persistent);
        }

        // Allocate scratch buffer to hold predictions. This is overwritten every time
        // a snapshot is being written to a specific client
        m_Prediction = (uint *)UnsafeUtility.Malloc(NetworkConfig.maxWorldSnapshotDataSize, UnsafeUtility.AlignOf <UInt32>(), Unity.Collections.Allocator.Persistent);
    }
Beispiel #8
0
        private void Run()
        {
            while (running)
            {
                try
                {
                    INetworkTransport transport = listener.AcceptClient(0);
                    logger.Info("New connection from : " + transport.RemoteEndPoint);

                    ClientConnection channel = ClientConnection.CreateClientConnection(transport, Envelope);
                    lock (clientLock)
                    {
                        clients.Add(channel);
                    }

                    OnChannelConnected(this, new ClientEventArgs(channel));
                    channel.ClientClosed += OnClientClosed;
                }
                catch (SocketException)
                {
                    // This is here because AcceptTcpClient throws an exception when we tell it
                    // stop listening.
                    logger.Debug("ChannelListener shutdown.  No longer accepting connections");
                }
                catch (IOException ex)
                {
                    logger.Warn(ex.Message, ex);
                    if (ex.InnerException != null)
                    {
                        logger.Warn("Inner Exception: " + ex.InnerException.Message, ex.InnerException);
                    }
                }
                catch (Exception ex)
                {
                    // Catch everything to make sure server remains running
                    logger.Fatal("Exception catchall: " + ex.Message, ex);
                    if (ex.InnerException != null)
                    {
                        logger.Fatal("Inner Exception: " + ex.InnerException.Message, ex.InnerException);
                    }
                    running = false;
                    listener.Stop();
                }
            }
        }
Beispiel #9
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");
                }
            }
        }
        public override async Task OnRTPPacket(byte[] packet)
        {
            RTPSessionState[] transports = null;
            lock (Sessions)
            {
                transports = Sessions.Values.ToArray();
            }


            foreach (var transport in transports)
            {
                INetworkTransport network  = transport.RTPTransport;
                IPEndPoint        endPoint = transport.RTPIPEndPoint;
                try
                {
                    bool success = await network.SendPacket(packet, endPoint);
                }

                catch (Exception ex)
                {
                    _logger.Error(ex);
                }
            }
        }
Beispiel #11
0
 /// <summary>
 /// Creates a controller channel with a transport that is able to handle incoming messages
 /// using the given envelope and dispatcher
 /// </summary>
 /// <param name="transport">A transport used to send/receive messages</param>
 /// <param name="envelope"></param>
 /// <param name="dispatcher">A MessageDispatcher to route messages to appropriate handlers</param>
 public ClientConnection(INetworkTransport transport, Envelope envelope, MessageDispatcher dispatcher)
 {
     Initialize(transport, envelope, dispatcher);
 }
Beispiel #12
0
 /// <summary>
 /// Creates a controller channel with a default TCP transport that is able to handle incoming messages
 /// using the given dispatcher
 /// </summary>
 /// <param name="transport">A transport used to send/receive messages</param>
 /// <param name="dispatcher">A MessageDispatcher to route messages to appropriate handlers</param>
 public ClientConnection(INetworkTransport transport, MessageDispatcher dispatcher)
 {
     Initialize(transport, new PlainEnvelope(), dispatcher);
 }
Beispiel #13
0
 /// <summary>
 /// Creates a controller channel with the given transport
 /// </summary>
 /// <param name="transport">The transport for the channel to communicate over</param>
 public Channel(INetworkTransport transport)
 {
     Initialize(transport, new PlainEnvelope(), new MessageDispatcher());
 }
Beispiel #14
0
 public NetworkClientManager(INetworkTransport transport, INetSerializer serializer) : base(transport)
 {
     msgManager = new MessageManager(serializer, false);
 }
Beispiel #15
0
 public NetworkClient(INetworkTransport transport)
 {
     m_Transport  = transport;
     clientConfig = new ClientConfig();
 }
        public static ClientConnection CreateClientConnection(MessageEnvelope envelope, INetworkTransport client)
        {
            ClientConnection connection = new ClientConnection(envelope, client);
            connection.StartReceiveThread();

            return connection;
        }
Beispiel #17
0
        public static ClientConnection CreateClientConnection(MessageEnvelope envelope, INetworkTransport client)
        {
            ClientConnection connection = new ClientConnection(envelope, client);

            connection.StartReceiveThread();

            return(connection);
        }
Beispiel #18
0
 public ClientConnection(INetworkTransport transport)
     : this(transport, new PlainEnvelope())
 {
 }
 public NetworkManagerBase(INetworkTransport transport)
 {
     this.transport = transport;
 }
 public NetworkServerManager(INetworkTransport transport, INetSerializer serializer) : base(transport)
 {
     msgManager = new MessageManager(serializer, true);
 }
Beispiel #21
0
 public ClientConnection(int connectionId, INetworkTransport transport, ClientConfig clientConfig) : base(connectionId, transport)
 {
     this.clientConfig = clientConfig;
 }
Beispiel #22
0
    public ushort outSequenceAckMask;               // The mask describing which of the last packaged have been acked related to outSequence

    public NetworkConnection(int connectionId, INetworkTransport transport)
    {
        ConnectionId = connectionId;
        Transport    = transport;
    }