我知道关于套接字还有一些其他问题,但没有真正为我工作。我是新手,我使用Python 3.4。套接字错误是什么意思,我该如何解决它们?
对于我的服务器上,这是我的代码:
import socket
s = socket.socket()
host = socket.gethostname()
port = 80
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()
我的客户端代码:
import socket
s = socket.socket()
host = socket.gethostname
port = 80
s.connect((host, port))
print (s.recv(1024))
s.close
对于服务器的代码,我得到了一个错误说:
Traceback (most recent call last):
File "/Users/Gautam/Documents/server.py", line 6, in <module>
s.bind((host, port))
PermissionError: [Errno 13] Permission denied
对于客户我有一个错误说:
Traceback (most recent call last):
File "/Users/Gautam/Documents/client.py", line 7, in <module>
s.connect((host, port))
ConnectionRefusedError: [Errno 61] Connection refused
尝试以管理员身份运行它 – Totodile