Python TCP套接字无法正常工作 [英] Python TCP Sockets Not Working Properly

查看:195
本文介绍了Python TCP套接字无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不久前,我问这个问题.我很惊讶没有人提出任何答案,因此,我很确定我的问题很少见.昨天,当我自我诊断问题时,我开始将点点滴滴连络起来.我的Twisted TCP服务器无法正常工作,IDLE在启动时由于套接字错误"而失败,并返回消息:"IDLE子进程:套接字错误:由于目标计算机主动拒绝它而无法建立连接",我得到了当我尝试运行连接到(本地)TCP服务器的(本地)TCP客户端时,出现相同的错误.

Not too long ago I asked this question. I was very surprised that no one came up with any answers, so I am pretty sure my issue is fairly rare. Yesterday, as I was self-diagnosing the issue, I began connecting the dots. My Twisted TCP server won't work, IDLE fails at startup because of a "Socket Error" and returns the message: "IDLE Subprocess: socket error: No connection could be made because the target machine actively refused it", and I get this same error when I try running a (local) TCP client connecting to a (local) TCP server.

因此,昨天我得出的结论是,这些不仅仅是单个问题,而是使用Python套接字创建和运行TCP端点的更大问题.请记住,我既在本地网络上运行又在本地运行的UDP服务器和客户端,所以我认为整个Socket模块都没有问题,而仅仅是TCP方面的​​问题.

So I came to the conclusion Yesterday, that these weren't just individual issues, but rather a larger issue with creating and running TCP endpoints using Python Sockets. Keep in mind, UDP servers and clients that I run both on a local network and locally work, so I don't think it's a problem with the Socket module as a whole, but just the TCP side of things.

我的计算机上的某些信息:Windows 64位,运行Python 2.7.9(出于某种原因,为32位),笔记本电脑通过(内置)无线网卡连接到网络. ISP是Comcast(如果有区别的话),而Router/Modem(多合一)是Comcast提供的TechniColor(如果有区别的话).

Some info on my computer: Windows 64bit, running Python 2.7.9 (for some reason, 32bit), Laptop connected to a network via (built in) Wireless card. ISP is Comcast (if it makes a difference), and the Router/Modem (it's an all-in-one) is a TechniColor provided by Comcast (again, if it makes a difference).

我尝试过的事情:

  • 重置我的.../etc/hosts文件
  • 2个月前重新安装了Python(尝试进行故障排除)
  • 关闭所有防火墙(我只有1个)
  • 除Microsoft Security Essentials之外没有其他防病毒软件
  • 当我仍然安装Bitdefender时,该问题仍然存在,但是我确定要安装它

我还在前面提到的上一个线程上进行了小型故障排除会话.使用TCP套接字时遇到的最大错误是: socket.error: [Errno 10061] No connection could be made because the target machine actively refused it.

I also went through a small troubleshooting session on the previous thread I mentioned earlier. The biggest error I get when using TCP Sockets is: socket.error: [Errno 10061] No connection could be made because the target machine actively refused it.

因此,有人对这里出了什么问题有个主意吗?谢谢.

So, anyone have an idea as to what's wrong here? Thanks.

好像我错过了一些东西,端口是45002,超出了默认Windows端口的范围,而且我很确定没有任何东西使用它,因为我已经能够运行该端口上的UDP服务器具有良好的效果.该端口也会转发端口,以防万一.

Looks like I missed something, the port is 45002, which is out of the range of default Windows ports, and I am pretty sure nothing uses it, as I have been able to run a UDP server on that port with good results. The port is also port forwarded, just in case.

推荐答案

出现错误由于目标计算机主动拒绝连接而无法建立连接"这一事实.意味着没有人在尝试连接的端口上监听.每当有人尝试连接到该IP @上没有人正在监听的端口时,TCP内核都会用RST响应,因此实际上您正在到达主机,但是主机不为该端口提供任何服务.

The fact that you get the error 'No connection could be made because the target machine actively refused it.' Means that nobody is listening on the port you are trying to connect to. A TCP kernel responds with a RST each time someone tries to connect to a port where nobody is listening, on that IP@ so you are in fact reaching the host, but the host is not servicing anything on the port.

您是否没有忘记启动服务器的机会?在您尝试连接的服务器计算机上运行netstat -a,以显示实际上正在监听的端口列表.

You did not forget to start your server by any chance ? Run netstat -a on the server machine you are trying to connect to so that it shows a list of ports it is in fact listening on.

这篇关于Python TCP套接字无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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