简体   繁体   English

Errno 10061在python中,我不知道该做些什么

[英]Errno 10061 in python, I don't know what do to

I learned sockets in python. 我在python中学习了套接字。 When I tried to programming sockets script in one computer, it worked, but when I tried to programming sockets script with two different computers and open socket with connection, it didn't work. 当我尝试在一台计算机上编写套接字脚本时,它工作正常,但是当我尝试使用两台不同的计算机编写套接字脚本并打开带有连接的套接字时,它无效。

One computer(the server): 一台计算机(服务器):

import socket

s = socket.socket()

host = socket.gethostname()
port = 1234
s.bind((host, port))

s.listen(5)
while True:
    c, addr = s.accept()
    print 'Got connection from', addr
    c.send('Thank you for connecting')
    c.close()

Second computer(the client): 第二台计算机(客户端):

import socket

s = socket.socket()

host = raw_input("The ip you want to connect to: ")
port = 1234

s.connect((host, port))
print s.recv(1024)

Error: 错误:

socket.error: [Errno 10061]

What is the problem in the scripts? 脚本中的问题是什么? Why it doesn't work? 为什么它不起作用?

Errno 10061: Errno 10061:

It means the server you are trying to connect to is not waiting for one. 这意味着您尝试连接的服务器不等待。

  • Make sure you have the port number open. 确保打开端口号。
  • Try killing all python processes and start server again. 尝试杀死所有python进程并再次启动服务器。

Update 更新

Instead of 代替

host = socket.gethostname()

use 使用

host = ""

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM