我试图用Python中的套接字连接两台计算机,我不知道为什么它不起作用。这些文件来自互联网,它为我编译,但没有任何结果。Python服务器客户端套接字
的server.py:
#!/usr/bin/python
import socket
s = socket.socket()
host = ''
port = 12345
s.bind((host, port))
s.listen(5)
while True:
c, addr = s.accept()
print 'Got connection from', addr
c.send('Thank you for connecting')
c.close()
和client.py:
#!/usr/bin/python
import socket
s = socket.socket()
host = # here I put the ip of the server's laptop
port = 12345
s.connect((host, port))
print s.recv(1024)
s.close()
有什么不对?
这不起作用,因为代码中存在语法错误。无论如何,代码从哪里来?我在问,因为它适用于旧的Python 2,并且可能已经过时。 –
http://www.tutorialspoint.com/python/python_networking.htm它来自这里。 – IleNea
你期待什么_results_?顺便说一句,你可以尝试用'sendall'替换'send'。 – ForceBru