Commit bb2edc6e authored by 簡碩辰's avatar 簡碩辰

Update run.py

parent cf92d410
import json, os, socket, time, subprocess as SP import json, os, socket, time, datetime, pytz, subprocess as SP
from paho.mqtt.client import Client as MQTT from paho.mqtt.client import Client as MQTT
def TryConnect(host, port): def TryConnect(host, port):
now = datetime.datetime.now(tz=pytz.timezone('Asia/Taipei'))
now = now.strftime('%Y/%m/%d %H:%M:%S')
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try: try:
s.connect((host, int(port))) s.connect((host, int(port)))
s.shutdown(socket.SHUT_RDWR) s.shutdown(socket.SHUT_RDWR)
return True return True
except ConnectionRefusedError: except ConnectionRefusedError:
print("Connect to {0}:{1} is refused.".format(host, port)) print("Connect to {0}:{1} is refused.".format(host, port))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment