0
我想創建一個腳本,錯誤時會嘗試重新連接。但即使在接收服務器已經開始仍然不會連接試圖在連接被拒絕後重新連接 - 蟒蛇
send_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
while True:
try: #Cant get it to make connection after retrying
send_sock.connect((ip, port)) #always throws Con Refused when tryed
break
except socket.error:
print "Connection Failed, Retrying.."
time.sleep(1)
send_sock.send("hi")
編輯:更正「嘗試:」錯字
我假設您在實際代碼中使用'try:'而不是'Try'(因爲'Try'不是有效的語法) – Chris
我在帖子中更正了try語句,謝謝。 – Gittb
什麼是當前輸出?它會引發錯誤嗎?即使連接失敗,它是否會到達'send_sock.send'行? – Chris