无法与目标网站服务器建立连接,Errno 10061:无法建立连接,因为目标计算机主动拒绝它(客户端 - 服务器)...

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

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

服务器:

#!/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:代码来自互联网.

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值