/// <summary> /// Function to process data off the tcp stream - called from the worker thread /// </summary> public void ReadStream() { try { MESSAGEFIX3Lib.FIXMessage msg = new FIXMessage(); char[] message = new char[1024]; while (m_bContinue) { int nSize = m_StreamIn.ReadBlock(message, 0, 1024); if (nSize <= 0) continue; #if DEBUG System.Diagnostics.Trace.WriteLine("In Buffer" + nSize); #endif m_sTCPBuffer.Append(message, 0, nSize); #if DEBUG System.Diagnostics.Trace.WriteLine(m_sTCPBuffer.ToString()); #endif bool bContinue = true; while(bContinue) { string sData = m_sTCPBuffer.ToString(); int nheader = sData.IndexOf("8="); int nTail = sData.IndexOf("10="); if (nTail <= 0) { bContinue = false; continue; } int nEnd = sData.IndexOf("!", nTail); int nEnd1 = sData.IndexOf("8=", nTail); if (nEnd1 == -1) { bContinue = false; } else { sData = sData.Substring(nheader, nEnd1 - nheader); #if DEBUG System.Diagnostics.Trace.WriteLine("Buffer Current" + m_sTCPBuffer.Length); #endif m_sTCPBuffer.Remove(0, nEnd1); #if DEBUG System.Diagnostics.Trace.WriteLine("Buffer Data Remainder" + m_sTCPBuffer.Length); #endif //find the specific string string sTemp = string.Empty; //parse fix messagge bool bSuccess = msg.Parse(sData, m_sDelimiter, false); if (bSuccess) { if (DataEvent != null) { DataEvent(this, new FIXMessageEventArgs(msg)); } } else { //Failed to parse data #if DEBUG System.Diagnostics.Trace.WriteLine("Parse Error = " + sTemp); #endif } //clear the object msg.Clear(); } } } } catch (Exception e) { //Log - raise an event if (DisconnectEvent != null) DisconnectEvent(new ErrorEventArgs(e)); } }