client端:

Private Function Receive(ByRef state As StateObject, ByVal Merch_ID As String, ByVal ULNm As String) As Boolean
On Error GoTo go_Err
Dim readStream As New NetworkStream(state.workSocket)
Dim blnReturn As Boolean = False
Dim intRcv As Integer
Dim strTmp As String = ""
state.buffer.Clear(state.buffer, 0, StateObject.BufferSize)
readStream.ReadTimeout = iTimeOutM
intRcv = readStream.Read(state.buffer, 0, StateObject.BufferSize)
Do While intRcv > 0
strTmp = Encoding.Default.GetString(state.buffer, 0, intRcv)
state.sb.Append(strTmp)
If ConfigurationManager.AppSettings("g_IsDebug") = "1" Then
Dim FileToWrite As = ("D:\程序\ESA_OPR_New\debug\Receive" + Merch_ID + "_" + ULNm + ".txt")
Dim rByte() As Byte = Encoding.Default.GetBytes(state.sb.ToString.ToCharArray)
FileToWrite.Write(rByte, 0, rByte.Length)
FileToWrite.Close()
FileToWrite = Nothing
End If
'不按照报文头字符长度来取报文体字段,因为在测试中发现WINDOWS与UNIX在中文和特殊字符的长度判断上不相同
'所以采用查找结束符号的方式来判断报文尾
If InStr(strTmp, "</PACKAGE>") > 0 Then
Exit Do
Else
state.buffer.Clear(state.buffer, 0, StateObject.BufferSize)
intRcv = readStream.Read(state.buffer, 0, StateObject.BufferSize)
End If
Loop
blnReturn = True
readStream = Nothing
go_Exit:
Return blnReturn
Exit Function
go_Err:
blnReturn = False
GoTo go_Exit
End Function