想发送字符串,如下:
接收端:
import socket
s = socket.socket()
host = socket.gethostname()
port = 13323
s.connect((host,port))
print(s.recv(1024).decode())
s.close()
发送端:
import socket
s = socket.socket()
host = socket.gethostname()
port = 13323
s.bind((host,port))
s.listen(5)
while True:
c,addr = s.accept()
print('连接地址:',addr)
str1 = '你好!'
c.send(str1.encode("utf8"))
c.close()
在一台电脑上试可以,分开就不行了,报错:
Traceback (most recent call last):
File "C:\Users\Administrator\Desktop\8888.py", line 5, in <module>
s.bind((host,port))
socket.gaierror: [Errno 11004] getaddrinfo failed
这个是怎么回事,求解答