似乎首页能访问,其他的不行
This commit is contained in:
parent
f73419e3eb
commit
acbe2d07bf
@ -3,6 +3,7 @@ import socket
|
|||||||
import threading
|
import threading
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
|
import inspect
|
||||||
|
|
||||||
TARGET_HOST = 'zentao.sunyard.com.cn'
|
TARGET_HOST = 'zentao.sunyard.com.cn'
|
||||||
TARGET_PORT = 9788
|
TARGET_PORT = 9788
|
||||||
@ -10,12 +11,16 @@ TARGET_PORT = 9788
|
|||||||
def log_info(source, message):
|
def log_info(source, message):
|
||||||
"""Log info message"""
|
"""Log info message"""
|
||||||
timestamp = time.strftime("%Y-%m-%d %H:%M:%S")
|
timestamp = time.strftime("%Y-%m-%d %H:%M:%S")
|
||||||
print("[%s] [INFO] [%s] %s" % (timestamp, source, message))
|
frame = inspect.currentframe().f_back
|
||||||
|
line = frame.f_lineno
|
||||||
|
print("[%s] [INFO] [%s] (line %d) %s" % (timestamp, source, line, message))
|
||||||
|
|
||||||
def log_error(source, message):
|
def log_error(source, message):
|
||||||
"""Log error message"""
|
"""Log error message"""
|
||||||
timestamp = time.strftime("%Y-%m-%d %H:%M:%S")
|
timestamp = time.strftime("%Y-%m-%d %H:%M:%S")
|
||||||
print("[%s] [ERROR] [%s] %s" % (timestamp, source, message))
|
frame = inspect.currentframe().f_back
|
||||||
|
line = frame.f_lineno
|
||||||
|
print("[%s] [ERROR] [%s] (line %d) %s" % (timestamp, source, line, message))
|
||||||
|
|
||||||
def handle_request(b_socket, request_data):
|
def handle_request(b_socket, request_data):
|
||||||
"""Handle a single request from device B"""
|
"""Handle a single request from device B"""
|
||||||
@ -134,8 +139,11 @@ def connect_to_b_device(b_host, b_port):
|
|||||||
|
|
||||||
listen_for_requests(sock)
|
listen_for_requests(sock)
|
||||||
|
|
||||||
except ConnectionRefusedError:
|
except socket.error as e:
|
||||||
|
if e.errno == 111 or e.errno == 10061:
|
||||||
log_info("System", "Device B not ready (%s:%d), retrying in 3 seconds..." % (b_host, b_port))
|
log_info("System", "Device B not ready (%s:%d), retrying in 3 seconds..." % (b_host, b_port))
|
||||||
|
else:
|
||||||
|
log_error("System", "Connection error: %s" % str(e))
|
||||||
time.sleep(3)
|
time.sleep(3)
|
||||||
except socket.timeout:
|
except socket.timeout:
|
||||||
log_info("System", "Connection timeout, retrying in 3 seconds...")
|
log_info("System", "Connection timeout, retrying in 3 seconds...")
|
||||||
@ -165,7 +173,11 @@ def main():
|
|||||||
print("Device B address:", b_host, ":", b_port)
|
print("Device B address:", b_host, ":", b_port)
|
||||||
print("=" * 60)
|
print("=" * 60)
|
||||||
|
|
||||||
|
try:
|
||||||
connect_to_b_device(b_host, b_port)
|
connect_to_b_device(b_host, b_port)
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
log_info("System", "Received Ctrl+C, exiting...")
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
|||||||
@ -2,6 +2,8 @@
|
|||||||
import socket
|
import socket
|
||||||
import threading
|
import threading
|
||||||
import time
|
import time
|
||||||
|
import sys
|
||||||
|
import inspect
|
||||||
|
|
||||||
PORT_FOR_A = 8080 # Port for device A to connect
|
PORT_FOR_A = 8080 # Port for device A to connect
|
||||||
PORT_FOR_BROWSER = 8081 # Port for browser to connect
|
PORT_FOR_BROWSER = 8081 # Port for browser to connect
|
||||||
@ -13,12 +15,16 @@ a_device_connected = threading.Event()
|
|||||||
def log_info(source, message):
|
def log_info(source, message):
|
||||||
"""Log info message"""
|
"""Log info message"""
|
||||||
timestamp = time.strftime("%Y-%m-%d %H:%M:%S")
|
timestamp = time.strftime("%Y-%m-%d %H:%M:%S")
|
||||||
print("[%s] [INFO] [%s] %s" % (timestamp, source, message))
|
frame = inspect.currentframe().f_back
|
||||||
|
line = frame.f_lineno
|
||||||
|
print("[%s] [INFO] [%s] (line %d) %s" % (timestamp, source, line, message))
|
||||||
|
|
||||||
def log_error(source, message):
|
def log_error(source, message):
|
||||||
"""Log error message"""
|
"""Log error message"""
|
||||||
timestamp = time.strftime("%Y-%m-%d %H:%M:%S")
|
timestamp = time.strftime("%Y-%m-%d %H:%M:%S")
|
||||||
print("[%s] [ERROR] [%s] %s" % (timestamp, source, message))
|
frame = inspect.currentframe().f_back
|
||||||
|
line = frame.f_lineno
|
||||||
|
print("[%s] [ERROR] [%s] (line %d) %s" % (timestamp, source, line, message))
|
||||||
|
|
||||||
def handle_browser(browser_conn, browser_addr):
|
def handle_browser(browser_conn, browser_addr):
|
||||||
"""Handle browser connection"""
|
"""Handle browser connection"""
|
||||||
@ -208,11 +214,17 @@ def main():
|
|||||||
|
|
||||||
t1 = threading.Thread(target=run_a_device_server)
|
t1 = threading.Thread(target=run_a_device_server)
|
||||||
t2 = threading.Thread(target=run_browser_server)
|
t2 = threading.Thread(target=run_browser_server)
|
||||||
|
t1.daemon = True
|
||||||
|
t2.daemon = True
|
||||||
t1.start()
|
t1.start()
|
||||||
t2.start()
|
t2.start()
|
||||||
|
|
||||||
t1.join()
|
try:
|
||||||
t2.join()
|
while True:
|
||||||
|
time.sleep(1)
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
log_info("System", "Received Ctrl+C, exiting...")
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user