0

好的,所以我正在开发这个程序,它向我的世界服务器发送一个数据包,作为回报,它给了我关于服务器的信息;(当日消息,在线玩家,最大玩家数)

问题是响应在 UCS-2 中

因此,当我将数据包发送到服务器并以字节为单位获得响应时。我如何将其转换为 ascii 以便我可以使用它?

到目前为止,这是我的代码

Dim client As New System.Net.Sockets.TcpClient()
client .Connect("178.33.213.54", 25565)

Dim stream As NetworkStream = client .GetStream



'Send Bytes
Dim sendBytes As [Byte]() = {&HFE}
stream.Write(sendBytes, 0, sendBytes.Length)

'Receive Bytes
Dim bytes(client .ReceiveBufferSize) As Byte
stream.Read(bytes, 0, CInt(leclient.ReceiveBufferSize))

'Convert it to ASCII
....


'Output it to Console
....

这是 PHP、python 和 ruby​​ 中的相同代码。


php -> https://gist.github.com/1235274


蟒蛇-> https://gist.github.com/1209061


红宝石-> http://pastebin.com/q5zFPcXV

文档在这里: http: //www.wiki.vg/Protocol#Server_List_Ping_.280xFE.29

提前致谢!
维杜

4

1 回答 1

2

测试和工作。

Dim client As New System.Net.Sockets.TcpClient()

client.Connect("178.33.213.54", 25565)

Dim stream As System.Net.Sockets.NetworkStream = client.GetStream

'Send Bytes
Dim sendBytes As [Byte]() = {&HFE}
stream.Write(sendBytes, 0, sendBytes.Length)

''Receive Bytes
Dim bytes(client.ReceiveBufferSize) As Byte
stream.Read(bytes, 0, CInt(client.ReceiveBufferSize))

Dim sb As New System.Text.StringBuilder
For i As Integer = 3 To bytes.GetUpperBound(0) Step 2
  Dim byt2(1) As Byte
  byt2(0) = bytes(i + 1)
  byt2(1) = bytes(i)

  Dim ii As Integer = BitConverter.ToInt16(byt2, 0)
  'sb.Append(Hex(ii)) 'debug
  sb.Append(ChrW(ii))
Next i
MsgBox(sb.ToString)
stream.Close()
于 2012-10-04T02:13:30.863 回答