socket通信问题
通过socket与UNIX主机进行通信,单个用户查询没问题,两个或两个以上用户同时进行查询,查询时间分别为30秒,第一个用户查询10秒后,第二个用户开始查询,两个用户得到的结果都是第一个用户的,或者第一个查不到,第二个查询显示的是第一个的查询结果,求原因。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