[英]Python Socket Programming ConnectionRefusedError: [Errno 61] Connection refused
This is my code for the server program: 这是我的服务器程序代码:
import socket
soket = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
HOST = "localhost"
PORT = 8011
soket.bind((HOST,PORT))
print("%s:%d server başlatıldı." % (HOST,PORT))
print("Kullanıcı bekleniyor.")
soket.listen(2)
baglanti,adres = soket.accept()
print("Bir bağlantı kabul edildi.", adres)
baglanti.send("Hoşgeldiniz efendim , hoşgeldiniz.")
data = baglanti.recv(1024)
print(data)
soket.close()
And this is for the client: 这是给客户的:
import socket
clientsocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
clientsocket.connect(("localhost", 8011))
clientsocket.send('hello')
Although I first start the server program and then the client program, I get this error: 尽管我先启动服务器程序,然后启动客户端程序,但出现此错误:
Traceback (most recent call last):
File "/Users/Esat/Desktop/Python/Softwares/socketto copy.py", line 3, in <module>
clientsocket.connect(("localhost", 8011))
ConnectionRefusedError: [Errno 61] Connection refused
Instead of localhost
, it is better to use LAN (local) IP. 代替localhost
,最好使用LAN(本地)IP。 You can get your local IP by running ipconfig (in Windows) or ifconfig
(in GNU/Linux or Mac OS). 您可以通过运行ipconfig(在Windows中)或ifconfig
(在GNU / Linux或Mac OS中)来获取本地IP。 Your local IP should be something like 192.168.1.x
. 您的本地IP应该类似于192.168.1.x
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.