/// <summary> /// Entrance point of the thread. /// This method run by thread to listen incoming data from communicator. /// </summary> private void DoCommunicateAsThread() { while (State == CommunicationStates.Connected || State == CommunicationStates.Connecting) { try { //Read a message from _networkStream (socket) and raise MessageReceived event OnMessageReceived( _wireProtocol.ReadMessage( new MDSDefaultDeserializer(_networkStream) )); } catch { //Stop listening on an error case break; } } //while //if socket is steel connected, then close it try { Disconnect(); } catch (Exception ex) { Logger.Debug(ex.Message, ex); } _thread = null; }
/// <summary> /// Entrance point of the thread. /// This method run by thread to listen incoming data from communicator. /// </summary> private void DoCommunicateAsThread() { Logger.Debug("TCPCommunicator thread is started. CommunicatorId=" + ComminicatorId); while (State == CommunicationStates.Connected || State == CommunicationStates.Connecting) { try { //Read a message from _networkStream (socket) and raise MessageReceived event var message = _wireProtocol.ReadMessage(new MDSDefaultDeserializer(_networkStream)); Logger.Debug("Message received by communicator " + ComminicatorId + ": " + message.GetType().Name); OnMessageReceived(message); } catch (Exception ex) { Logger.Error(ex.Message, ex); break; //Stop listening } } //if socket is still connected, then close it try { Stop(false); } catch (Exception ex) { Logger.Warn(ex.Message, ex); } Logger.Debug("TCPCommunicator is stopped. CommunicatorId=" + ComminicatorId); _thread = null; }