无法建立连接,因为目标机器主动拒绝它 [英] No connection could be made because the target machine actively refused it

查看:38
本文介绍了无法建立连接,因为目标机器主动拒绝它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每次尝试运行我的程序时,我都尝试连接到本地计算机.我是个笨蛋,所以这可能是某个地方的一个简单错误.

I've tried to connect to my local machine every time I try and run my program. I am a nub, so it's probably a simple mistake somewhere.

def connect(self):
    self.conn = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    self.conn.connect((self.host,self.port))

那是导致错误的代码.定义了主机和端口.为什么它给我这个错误报告?

That is the code causing the error. The host and port are defined. Why is it giving me this error report?

[Errno 10061] 无法建立连接,因为目标机器主动拒绝

[Errno 10061] No connection could be made because the target machine actively refused it

推荐答案

这是因为您还没有打开您尝试连接的端口,那里没有任何东西在侦听.如果您尝试连接到 Web 或 ftp 服务器,请先启动它.如果您尝试连接到另一个端口,则还需要编写一个服务器应用程序.

It's because you haven't opened the port you are trying to connect to, nothing is listening there. If you're trying to connect to a web or ftp server, start it first. If you're trying to connect to another port, you need to write a server application too.

这篇关于无法建立连接,因为目标机器主动拒绝它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆