본문 바로가기

[공부용]참고 사이트 모음/[python]

python 소켓 연결 예외처리 타임아웃 설정 - Python socket connection exception

출처 stackoverflow.com/questions/25447803/python-socket-connection-exception

 

Python socket connection exception

I have a socket-connection going on and I wanna improve the exception handling and Im stuck. Whenever I use the socket.connect(server_address) function with an invalid argument the program stops, but

stackoverflow.com

import socket

s = socket.socket()
s.settimeout(5)   # 5 seconds
try:
    s.connect(('123.123.123.123', 12345))         # "random" IP address and port
except socket.error, exc:
    print "Caught exception socket.error : %s" % exc

소켓 연결 디폴트 연결 시도시간 120초 

줄이고 싶다면 settimeout() 이용