Example #1
0
        private void DoListenForClients(object state, CancellationToken token)
        {
            TcpListener _server = (state as TcpListener);

            while (!cancelListenToken.IsCancellationRequested)
            {
                logger.Info("Waiting for a connection... ");

                // Perform a blocking call to accept requests.
                TcpClient tcpClient = _server.AcceptTcpClient();
                // Get ID
                string id = GetIDFromSocket(tcpClient.Client);
                // Create Framewrapper
                var framewrapper = new T();
                // Create TCPNetCommunicator
                CommunicatorBase <U> communicator = new TCPNETCommunicator <U>(tcpClient, framewrapper, UseCircularBuffers);

                // Add to dict
                lock (lockerClientList)
                    ClientList.Add(id, communicator);

                // Subscribe to events
                communicator.ConnectionStateEvent += OnCommunicatorConnection;
                communicator.DataReadyEvent       += OnCommunicatorData;
                framewrapper.FrameAvailableEvent  += OnFrameReady;

                communicator.Init(null, false, id, 0);
                framewrapper.Start();
                communicator.Start();
            }
        }
        public void Connect(ConnUri cameraUri)
        {
            if (_communicator != null)
            {
                _viscaFrameWrapper.FrameAvailableEvent -= OnMessage;
                _viscaFrameWrapper.Dispose();
                _viscaFrameWrapper = null;

                _communicator.ConnectionStateEvent -= OnConnection;
                _communicator.Dispose();
                _communicator = null;
            }

            _viscaFrameWrapper = new ViscaFrameWrapper();
            _viscaFrameWrapper.FrameAvailableEvent += OnMessage;
            _communicator = new TCPNETCommunicator <BaseMessage>(_viscaFrameWrapper);
            _communicator.ConnectionStateEvent += OnConnection;
            _communicator.Init(cameraUri, true, ID, 0);

            _communicator.Start();
        }