Errno 10061:无法建立连接,因为目标机器主动拒绝它(客户端-服务器) [英] Errno 10061 : No connection could be made because the target machine actively refused it ( client - server )

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

问题描述

我对这些客户端和服务器代码有问题,我不断收到[Errno 10061] 无法建立连接,因为目标机器主动拒绝

I have a problem with these client and server codes, I keep getting the [Errno 10061] No connection could be made because the target machine actively refused it

我在带有 Windows XP SP3 的虚拟机和 Windows 7 64 位客户端上运行服务器,我的 python 版本是 2.7.3.我想知道的是我应该如何编辑代码以在不同网络上使用客户端和服务器!谢谢!

I'm running the server on a virtual machine with Windows XP SP3 and the client on Windows 7 64bit, my python version is 2.7.3. What I want to know is how should I edit the code to use the client and server on different networks! Thanks!

服务器:

#!/usr/bin/python           # This is server.py file

import socket               # Import socket module
s = socket.socket()         # Create a socket object
host = '0.0.0.0' # Get local machine name
port = 12345                # Reserve a port for your service.


print 'Server started!'
print 'Waiting for clients...'

s.bind((host, port))        # Bind to the port
s.listen(5)                 # Now wait for client connection.
c, addr = s.accept()     # Establish connection with client.
print 'Got connection from', addr
while True:
  msg = c.recv(1024)
  print addr, ' >> ', msg
  msg = raw_input('SERVER >> ')
  c.send(msg);
  #c.close()                # Close the connection

客户:

#!/usr/bin/python           # This is client.py file

import socket               # Import socket module

s = socket.socket()         # Create a socket object
host = socket.gethostname() # Get local machine name
port = 12345                # Reserve a port for your service.

print 'Connecting to ', host, port
s.connect((host, port))

while True:
  msg = raw_input('CLIENT >> ')
  s.send(msg)
  msg = s.recv(1024)
  print 'SERVER >> ', msg
#s.close                     # Close the socket when done

PS:代码来自网络.

推荐答案

10061 是 WSAECONNREFUSED,连接被拒绝",这意味着没有任何东西在您尝试连接的 IP:port 上监听.

10061 is WSAECONNREFUSED, 'connection refused', which means there was nothing listening at the IP:port you tried to connect to.

大约在 2000 年左右,有一款防火墙产品会发出拒绝消息,而不是忽略到被阻止端口的传入连接,但这很快就被识别为向攻击者泄露信息并予以纠正或撤回.

There was a firewall product around the year 2000 that issued refusals instead of ignoring incoming connections to blocked ports, but this was quickly recognised as an information leak to attackers and corrected or withdrawn.

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

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