你如何通过python套接字发送数字?

时间:2013-11-24 18:55:09

标签: python sockets

我尝试发送4个字符的填充数字,但是当我发送

# sender
number = str(2).zfill(4)
sending_socket.send(number)



# receiver      
msg = receiving_socket.recv(4)
print msg

打印的消息为11。

1 个答案:

答案 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'