0

我有这个System.Net.Sockets.TcpClient。我可以建立连接并将数据包准确地写入它。问题是要按原样读取数据包(被嗅探器以十六进制形式捕获,如 0F 03 56 56 等)

我尝试查看示例,GetStream.write但我没有以这种方式阅读它们。我还尝试使用流式阅读器,然后将数据包转换为十六进制,但我连接的东西发送搞砸的数据包,这些数据包无法转换或简单的不是字符串形式。

我希望我足够清楚。

Dim bytes(tcpClient.ReceiveBufferSize) As Byte 
' Read can return anything from 0 to numBytesToRead. 
' This method blocks until at least one byte is read. 
netStream.Read(bytes, 0, CInt(tcpClient.ReceiveBufferSize)) 
' Returns the data received from the host to the console. 
Dim returndata As String = Encoding.ASCII.GetString(bytes) 
4

1 回答 1

0

找到了解决方案!这里是:

Dim Bytes() as Byte = New Byte(1024){}
Array.Resize(Bytes, TcpClient.Client.Receive(Bytes, SocketFlags.None))

For Each B As Byte In Bytes
    Debug.Print("Byte in HEX Format: " & B.ToString("X2"))
Next
于 2012-07-15T03:29:54.900 回答