我在这方面相当天真。我不确定为什么我的连接超时。提前致谢。
#!/usr/bin/env python
import socket
def socket_to_me():
socket.setdefaulttimeout(2)
s = socket.socket()
s.connect(("192.168.95.148",21))
ans = s.recv(1024)
print(ans)
此代码生成的回溯
Traceback (most recent call last):
File "logger.py", line 12, in <module>
socket_to_me()
File "/home/drew/drewPlay/python/violent/networking.py", line 7, in socket_to_me
s.connect(("192.168.95.148",21))
File "/usr/lib/python2.7/socket.py", line 224, in meth
return getattr(self._sock,name)(*args)
timeout: timed out