简体   繁体   English

拒绝连接

[英]connection refused

What causes the folowing problem: 导致以下问题的原因:

>>> s = socket(AF_INET, SOCK_STREAM)
>>> s
<socket._socketobject object at 0x104a7a670>
>>> gethostname()
'MacBook-Air-user.local'
>>> s.connect((gethostname(), 4444))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py", line 224, in meth
    return getattr(self._sock,name)(*args)
socket.error: [Errno 61] Connection refused
>>> s.connect((gethostname(), 4444))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py", line 224, in meth
    return getattr(self._sock,name)(*args)
socket.error: [Errno 22] Invalid argument
>>> s.bind((gethostname(), 4446))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py", line 224, in meth
    return getattr(self._sock,name)(*args)
socket.error: [Errno 22] Invalid argument

On the system: 在系统上:

MacBook-Air-user:source user$ uname -a
Darwin MacBook-Air-user.local 11.4.0 Darwin Kernel Version 11.4.0: Mon Apr  9 19:32:15 PDT 2012; root:xnu-1699.26.8~1/RELEASE_X86_64 x86_64

You are trying to open a network connection to your computer on port 4444, but there is no server listening on that port 您正在尝试通过端口4444打开与计算机的网络连接,但是该端口上没有服务器在监听

see the socket example at http://docs.python.org/library/socket.html#example 请参阅http://docs.python.org/library/socket.html#example上的套接字示例

它应该是socket.gethostname()

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

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