我尝试发送4个字符的填充数字,但是当我发送
时# sender
number = str(2).zfill(4)
sending_socket.send(number)
# receiver
msg = receiving_socket.recv(4)
print msg
打印的消息为11。
答案 0 :(得分:1)
你有些事情没有让我们错了:
# sender
>>> from socket import *
>>> s=socket()
>>> s.connect(('localhost',8000))
>>> number=str(2).zfill(4)
>>> s.send(number)
# receiver
>>> from socket import *
>>> s=socket()
>>> s.bind(('',8000))
>>> s.listen(1)
>>> c,a=s.accept()
>>> c.recv(4)
'0002'