简体   繁体   English

Python套接字编程ConnectionRefusedError:[Errno 61]连接被拒绝

[英]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.

相关问题 Python 套接字'ConnectionRefusedError:[Errno 61]' - Python Socket 'ConnectionRefusedError: [Errno 61]' Ftplib ConnectionRefusedError: [Errno 111] 连接被拒绝 (python 3.5) - Ftplib ConnectionRefusedError: [Errno 111] Connection refused (python 3.5) python-valve rcon minecraft&#39;ConnectionRefusedError:[Errno 111]连接被拒绝&#39; - python-valve rcon minecraft 'ConnectionRefusedError: [Errno 111] Connection refused' Python 请求库的新手,获取“[Errno 61] 连接被拒绝” - New to Python requests library, getting '[Errno 61] Connection refused' 在Python(多处理)中正确酸洗和取消代理对象? “ConnectionRefusedError:[Errno 111] 解压时连接被拒绝” - Properly pickling and unpickling proxy objects in Python (multiprocessing)? "ConnectionRefusedError: [Errno 111] Connection refused while unpickling" 连接到SAP HANA:ConnectionRefusedError:[Errno 111]连接被拒绝 - connecting to SAP HANA : ConnectionRefusedError: [Errno 111] Connection refused PythonAnywhere ConnectionRefusedError:[Errno 111] 与 Twilio 一起使用时连接被拒绝 - PythonAnywhere ConnectionRefusedError: [Errno 111] Connection refused when used with Twilio 使用 WebRTC 的 GPU 加速流未连接 [ConnectionRefusedError: [Errno 111] Connection denied] - GPU-accelerated streaming using WebRTC not connecting [ConnectionRefusedError: [Errno 111] Connection refused] python编程发送电子邮件 - ConnectionRefusedError: [WinError 10061] 无法建立连接 - python programming to send an email - ConnectionRefusedError: [WinError 10061] No connection could be made 连接到远程数据库后,迁移会出现错误:Errno61,拒绝连接 - After connecting to remote database, migrating gives error: Errno61, Connection Refused
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM