我會得到球滾動:
import socket
import struct
username = "username_value"
verification_key = "verification_key"
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) # boilerplate
s.connect(("example.com", 1234)) # adjust accordingly
# now for the packet
# note that the String type is specified as having a length of 64, we'll pad that
packet = ""
packet += struct.pack("B", 1) # packet type
packet += struct.pack("B", 7) # protocol version
packet += "%-64s" % username # magic!
packet += "%-64s" % verification_key
packet += struct.pack("B", 0) # that unused byte, assuming a NULL byte here
# send what we've crafted
s.send(packet)
的「%-20s」如果你從來沒有用過的格式字符串可能會奇怪你。基本上..
print "%s" % 5
..將打印出5 ..
print "%10s" % 5
..將墊的輸出是在寬度恰好10個字符。但他們墊在右側,我們要的是填充在左側 - 因此-
..
print "%-10s" % s, "<this will be 9 spaces away from the '5'>"
..玩它。
如果有什麼不清楚的地方,請告訴我。我喜歡你在做什麼,讓我想起我的一箇舊項目。除了我沒有像你那樣的整潔的協議規範,幸運的混蛋。 ;)
非常感謝!這正是我想要的,不可能更有幫助。 – Jack 2012-03-01 18:40:39
你好,你能幫我嗎?當我嘗試連接到MC Classic Server時,它會給我錯誤響應'不兼容的客戶端或網絡錯誤。我該怎麼辦? – JadedTuna 2013-08-20 10:10:56