Server端收到網路封包後 的 ECHO 方法
'===============================
Private Sub ReceiveData(ByVal state As Object)
Dim myObj As New CSState
myObj.ClientSocket = CType(state, CSState).ClientSocket
myObj.myTcpListener = CType(state, CSState).myTcpListener
myObj.mystring = ""
Dim myNetworkStream As New NetworkStream(myObj.ClientSocket)
Dim InBytesCount As Integer = 0
Dim myReceiveBytes(1023) As Byte
Dim i As Integer = 0
While True
Try
InBytesCount = myNetworkStream.Read(myReceiveBytes, 0, myReceiveBytes.Length)
'InBytesCount =接收數據的數量
System.Threading.Thread.Sleep(100)
If InBytesCount = 0 Then '都沒有收到的話 結束掉while
Exit While
Else
' myNetworkStream.Write(myReceiveBytes, 0, InBytesCount) 'JKFIX: echo回去
myObj.mystring = Encoding.GetEncoding(950).GetString(myReceiveBytes).TrimEnd().TrimStart()
'--------------------
MsgBox(myObj.mystring.Length.ToString)
DB_list.rec_content = myObj.mystring.Substring(0, 4).Trim '/很奇怪必須指定字串長度 不然後續產生空白 長度大小會變1024
DB_list.rfid = DB_list.rec_content
' MsgBox(DB_list.rfid)
Try
DB_list.writeDB(DB_list.rec_content) 'jk加入 停車資料庫進出場查詢
'----JK echo now_money-------
Dim aaa As String = DB_list.now_money
Dim echo_bytes = Encoding.ASCII.GetBytes(aaa) 'string要先轉換成bytes
myNetworkStream.Write(echo_bytes, 0, echo_bytes.length) 'JKFIX: echo回去
'-----------
Catch ex As Exception
MsgBox(ex.ToString)
End Try
'---------------
DisplayMsg1(myObj)
End If
Catch ex As Exception
MessageBox.Show(ex.ToString)
Exit Sub
End Try
End While
End Sub
- Oct 03 Mon 2011 15:36
vbnet~ Server端收到網路封包後 的 ECHO 方法
close
全站熱搜
留言列表
禁止留言