0
我在C#下面的代碼:Socket編程 - 發送/接收十六進制和字符串
Console.WriteLine("Connecting to server...");
TcpClient client = new TcpClient("127.0.0.1", 25565);
client.Client.Send(BitConverter.GetBytes(0x02));
client.Client.Send(BitConverter.GetBytes(0x0005));
client.Client.Send(Encoding.UTF8.GetBytes("wedtm"));
Console.Write("{0:x2}", client.GetStream().ReadByte());
對於我的生活,我無法弄清楚如何轉這個紅寶石。這裏有幫助嗎?
這是我到目前爲止,但預計它不工作:
require 'socket'
s = TCPSocket.open("127.0.0.1", 25565)
s.write(0x02)
s.write(0x0005)
s.write("wedtm".bytes)
response = s.recvfrom(2)
puts "Response Size #{response.size}: #{response.to_s}"
的反應應該是0×02
編輯:
我假設我必須使用字符串#unpack然而,我不知道如何讓「wedtm」輸出到適當的\x000\x000\x000\x000
格式。
沒什麼,它是空白的。 – WedTM 2010-10-27 05:31:40