似乎首页能访问,其他的不行
This commit is contained in:
+16
-4
@@ -2,6 +2,8 @@
|
||||
import socket
|
||||
import threading
|
||||
import time
|
||||
import sys
|
||||
import inspect
|
||||
|
||||
PORT_FOR_A = 8080 # Port for device A 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):
|
||||
"""Log info message"""
|
||||
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):
|
||||
"""Log error message"""
|
||||
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):
|
||||
"""Handle browser connection"""
|
||||
@@ -208,11 +214,17 @@ def main():
|
||||
|
||||
t1 = threading.Thread(target=run_a_device_server)
|
||||
t2 = threading.Thread(target=run_browser_server)
|
||||
t1.daemon = True
|
||||
t2.daemon = True
|
||||
t1.start()
|
||||
t2.start()
|
||||
|
||||
t1.join()
|
||||
t2.join()
|
||||
try:
|
||||
while True:
|
||||
time.sleep(1)
|
||||
except KeyboardInterrupt:
|
||||
log_info("System", "Received Ctrl+C, exiting...")
|
||||
sys.exit(0)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user