socket.accept()在cygwin中运行脚本时不起作用



我尝试在Cygwin中运行基本的Python TCP服务器。但是以某种方式插座。Accept()方法失败了。该服务器似乎很活跃,因为在键入地址127.0.0.1:8080在浏览器中浏览器正在加载...

之后,我尝试了普通cmd.exe中的脚本,并且效果很好。有人对此有解释?

在这里我的代码:

import socket
# create a socket object
serversocket = socket.socket(
            socket.AF_INET, socket.SOCK_STREAM)
# get local machine name
host = '127.0.0.1'
port = 9999
# bind to the port
serversocket.bind((host, port))
# queue up to 5 requests
serversocket.listen(5)
while True:
    # establish a connection
    clientsocket,addr = serversocket.accept()
    print("Got a connection from %s" % str(addr))
    msg='Thank you for connecting'+ "rn"
    clientsocket.send(msg.encode('ascii'))
    clientsocket.close()

从2018年4月4日快照安装cygwin1.dll后,问题就解决了,

https://cygwin.com/snapshots/。

感谢Corinna Vinschen和Mark Geisert的后续行动,

https://cygwin.com/ml/cygwin/2018-04/msg00019.html

我通过发送TCP请求来复制该问题,

$ { echo test; sleep 1; } | /cygdrive/c/util/nc/nc.exe -v -w 2 127.0.0.1 9999
HOSTNAME [127.0.0.1] 9999 (?) open

让您的Python代码聆听时,

$ python accept.py
Traceback (most recent call last):
  File "accept.py", line 20, in <module>
    clientsocket,addr = serversocket.accept()
  File "/usr/lib/python2.7/socket.py", line 206, in accept
    sock, addr = self._sock.accept()
socket.error: [Errno 14] Bad address

不确定这是否相关,但是在观察到startxwin错误之后,我来到了您的帖子(当Xwin收到X11客户端(例如Xterm)的连接请求时),

_XSERVTransSocketUNIXAccept: accept() failed

sshd(将上述测试请求发送到端口22之后),

C:cygwin64>c:cygwin64usrsbinsshd.exe -ddd
debug2: load_server_config: filename /etc/sshd_config
debug2: load_server_config: done config len = 209
debug2: parse_server_config: config /etc/sshd_config len 209
debug3: /etc/sshd_config:54 setting AuthorizedKeysFile .ssh/authorized_keys
debug3: /etc/sshd_config:126 setting Subsystem sftp     /usr/sbin/sftp-server
debug1: sshd version OpenSSH_7.6, OpenSSL 1.0.2n  7 Dec 2017
debug1: private host key #0: ssh-rsa SHA256:XXXXXXX
debug1: private host key #1: ssh-dss SHA256:XXXXXXX
debug1: private host key #2: ecdsa-sha2-nistp256 SHA256:XXXXXXX
debug1: private host key #3: ssh-ed25519 SHA256:XXXXXXX
debug1: rexec_argv[0]='/usr/sbin/sshd'
debug1: rexec_argv[1]='-ddd'
debug2: fd 3 setting O_NONBLOCK
debug3: sock_set_v6only: set socket 3 IPV6_V6ONLY
debug1: Bind to port 22 on ::.
Server listening on :: port 22.
debug2: fd 4 setting O_NONBLOCK
debug1: Bind to port 22 on 0.0.0.0.
Server listening on 0.0.0.0 port 22.
accept: Bad address

有些观察到类似的错误地址,但他们的错误是通过2014年的Cygwin快照解决了,或者安装了32位Cygwin。我想知道后者是否与Windows中的WOW64错误有关,

http://zachsaw.blogspot.ca/2010/11/wow64-bug-getthreadcontext-may-return.html

$ uname -a
CYGWIN_NT-6.1 XXXXXX 2.10.1(0.325/5/3)  x86_64 Cygwin

最新更新