/// <summary> /// Connects the <see cref="ZeroMQClient"/> to the server asynchronously. /// </summary> /// <exception cref="InvalidOperationException">Attempt is made to connect the <see cref="ZeroMQClient"/> when it is not disconnected.</exception> /// <returns><see cref="WaitHandle"/> for the asynchronous operation.</returns> public override WaitHandle ConnectAsync() { m_connectionHandle = (ManualResetEvent)base.ConnectAsync(); m_zeroMQClient.SetReceiveBuffer(ReceiveBufferSize); m_connectionThread = new Thread(OpenSocket); m_connectionThread.IsBackground = true; m_connectionThread.Start(); return(m_connectionHandle); }
private void ReceiveDataHandler() { while (Enabled) { Guid clientID = Guid.Empty; TransportProvider <DateTime> clientInfo = null; try { // Receive data from the socket using (ZMessage message = m_zeroMQServer.ReceiveMessage()) { // Router socket should provide identity, delimiter and data payload frames if (message.Count == 3) { // Extract client identity clientID = new Guid(message[0].ReadStream()); // Lookup client info, adding it if it doesn't exist clientInfo = GetClient(clientID); // Get data payload frame ZFrame frame = message[2]; clientInfo.BytesReceived = (int)frame.Length; if (clientInfo.ReceiveBufferSize < clientInfo.BytesReceived) { clientInfo.SetReceiveBuffer(clientInfo.BytesReceived); } frame.Read(clientInfo.ReceiveBuffer, 0, clientInfo.BytesReceived); clientInfo.Statistics.UpdateBytesReceived(clientInfo.BytesReceived); // Update last client activity time clientInfo.Provider = DateTime.UtcNow; } } // Notify consumer of received data if ((object)clientInfo != null) { OnReceiveClientDataComplete(clientID, clientInfo.ReceiveBuffer, clientInfo.BytesReceived); } } catch (Exception ex) { OnReceiveClientDataException(clientID, ex); } } }
/// <summary> /// Connects the <see cref="FileClient"/> to the <see cref="FileStream"/> asynchronously. /// </summary> /// <exception cref="InvalidOperationException">Attempt is made to connect the <see cref="FileClient"/> when it is not disconnected.</exception> /// <returns><see cref="WaitHandle"/> for the asynchronous operation.</returns> public override WaitHandle ConnectAsync() { m_connectionHandle = (ManualResetEvent)base.ConnectAsync(); m_fileClient.SetReceiveBuffer(ReceiveBufferSize); #if ThreadTracking m_connectionThread = new ManagedThread(OpenFile); m_connectionThread.Name = "GSF.Communication.FileClient.OpenFile()"; #else m_connectionThread = new Thread(OpenFile); #endif m_connectionThread.Start(); return(m_connectionHandle); }
/// <summary> /// Connects the <see cref="SerialClient"/> to the <see cref="SerialPort"/> asynchronously. /// </summary> /// <exception cref="InvalidOperationException">Attempt is made to connect the <see cref="SerialClient"/> when it is connected.</exception> /// <returns><see cref="WaitHandle"/> for the asynchronous operation.</returns> public override WaitHandle ConnectAsync() { m_connectionHandle = (ManualResetEvent)base.ConnectAsync(); m_serialClient.SetReceiveBuffer(ReceiveBufferSize); m_serialClient.Provider = new SerialPort(); #if !MONO m_serialClient.Provider.ReceivedBytesThreshold = m_receivedBytesThreshold; #endif m_serialClient.Provider.DataReceived += SerialPort_DataReceived; m_serialClient.Provider.ErrorReceived += SerialPort_ErrorReceived; m_serialClient.Provider.PortName = m_connectData["port"]; m_serialClient.Provider.BaudRate = int.Parse(m_connectData["baudrate"]); m_serialClient.Provider.DataBits = int.Parse(m_connectData["databits"]); m_serialClient.Provider.Parity = (Parity)(Enum.Parse(typeof(Parity), m_connectData["parity"], true)); m_serialClient.Provider.StopBits = (StopBits)(Enum.Parse(typeof(StopBits), m_connectData["stopbits"], true)); if (m_connectData.ContainsKey("dtrenable")) { m_serialClient.Provider.DtrEnable = m_connectData["dtrenable"].ParseBoolean(); } if (m_connectData.ContainsKey("rtsenable")) { m_serialClient.Provider.RtsEnable = m_connectData["rtsenable"].ParseBoolean(); } #if ThreadTracking m_connectionThread = new ManagedThread(OpenPort); m_connectionThread.Name = "GSF.Communication.SerialClient.OpenPort()"; #else m_connectionThread = new Thread(OpenPort); #endif m_connectionThread.Start(); return(m_connectionHandle); }