2012-09-12 295 views
0

是什麼原因導致瞭如下因素的問題:連接被拒絕

>>> 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 

在系統:

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 
+5

沒有偵聽端口,或者防火牆/連接問題。 – Mat

回答