I’m fairly naive in this regard. I’m not sure why my connection is timing out. Thanks in advance.
#!/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)
the trace back generated by this code
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
You don’t need to alter the default timeouts for all new sockets, instead you can just set the timeout of that particular connection. The value is a bit low though, so increasing it to 10-15 seconds will hopefully do the trick.
First, do this:
Then:
And you should use “try:” on the connect, and add:
This will bring up the systems error message in your output and handle the exception.
Modified version of your code: