/// <summary> /// Get data from the socket /// </summary> /// <param name="expectLongResponse">flag indicates whether to expect a long response or not</param> /// <param name="writer">used for writing the response from the server</param> /// <returns>returns true if the operation was successful and false if an error occured</returns> private void GetData(bool expectLongResponse, TextWriter writer) { int iBytes; sb.Length = 0; bool bFirstLine = true; bool bLookForDotEnd = false; bool bError = false; do { try { // We use Receive so we don't have to wait for timeouts at the // end of variable-sized responses from the NNTP server. iBytes = socket.Receive(bRecv, 0, bRecv.Length); for (int i = 0; i < iBytes; i++) { bRecvChars[i] = (char)bRecv[i]; } writer.Write(bRecvChars, 0, iBytes); //sb.Append(bRecvChars,0,iBytes); if (bFirstLine) { if (sb.Length >= 3) { string codeString = sb.ToString(0, 3); int code = Convert.ToInt32(codeString); bFirstLine = false; if (code < 299) { if (expectLongResponse) { bLookForDotEnd = true; } } else { bError = true; } } } if (bLookForDotEnd && sb.Length >= 5 && sb.ToString(sb.Length - 5, 5) == "\r\n.\r\n") { break; } if ((bError || !expectLongResponse) && sb.Length >= 2 && sb.ToString(sb.Length - 2, 2) == "\r\n") { break; } } catch (Exception ex) { throw new NntpWebException(ex.Message, ex); } }while(iBytes > 0); }