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 static CommunicatorBase <T> CreateCommunicator <T>(ConnUri uri, FrameWrapperBase <T> frameWrapper, bool circular = false) { CommunicatorBase <T> c = null; switch (uri.UriType) { case ConnUri.TYPE.TCP: c = new TCPNETCommunicator <T>(frameWrapper, circular); break; case ConnUri.TYPE.UDP: c = new UDPNETCommunicator <T>(frameWrapper, circular); break; } return(c); }
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(); }