diff options
author | Zader Zheng <[email protected]> | 2015-04-17 14:01:13 +0800 |
---|---|---|
committer | Zader Zheng <[email protected]> | 2015-04-17 14:01:13 +0800 |
commit | f940101ae940604b56da1e3c263736a93adc3d3d (patch) | |
tree | 4ea0cdd5020eba40d282c535ea146f4b9c9c6ad7 | |
parent | 7533cded3f76380e6aa671affa0dc8d96a8d9a0f (diff) |
substitute TCP socket for UNIX socket
-rw-r--r-- | lab_monitor_client.py | 8 | ||||
-rw-r--r-- | lab_monitor_server.py | 16 |
2 files changed, 12 insertions, 12 deletions
diff --git a/lab_monitor_client.py b/lab_monitor_client.py index 194b927..b61170c 100644 --- a/lab_monitor_client.py +++ b/lab_monitor_client.py @@ -1,4 +1,4 @@ -from socket import socket, AF_UNIX +from socket import socket, AF_INET, SOCK_STREAM from struct import pack, unpack from sys import stdout, stdin import argparse @@ -10,6 +10,8 @@ parser.add_argument('--clear') parser.add_argument('--drop') parser.add_argument('--alter') parser.add_argument('--type') +parser.add_argument('--host', default='127.0.0.1') +parser.add_argument('--port', default='2334', type=int) parser.add_argument('col', nargs='*') args = parser.parse_args() @@ -42,8 +44,8 @@ if __name__ == '__main__': print('please specify an action') exit(1) - s = socket(AF_UNIX) - s.connect("./lab_monitor.socket") + s = socket(AF_INET, SOCK_STREAM) + s.connect((args.host, args.port)) mesg = json.dumps(cmd) mesg = pack("<i", len(mesg)) + mesg s.send(mesg) diff --git a/lab_monitor_server.py b/lab_monitor_server.py index 4207eb9..6a11da6 100644 --- a/lab_monitor_server.py +++ b/lab_monitor_server.py @@ -1,6 +1,7 @@ import time, json, os, re import logging, threading -from socket import socket, AF_UNIX, SHUT_WR, error as SocketError +from socket import socket, AF_INET, SOCK_STREAM, SHUT_WR, error as SocketError +import socket from struct import pack, unpack from time import sleep from tornado import gen @@ -13,7 +14,8 @@ logging.basicConfig(level=logging.DEBUG, MAX_LENGTH = 65536 MAX_RECORDS = 32 PORT = 2333 -local_socket_address = "./lab_monitor.socket" +SOCKET_PORT = 2334 +HOST = '' lock = RWLock() stat_res = {} @@ -88,13 +90,8 @@ action_map = {"create": add_monitor, def command_server(): global c, cmd_socket, is_exiting - try: - os.unlink(local_socket_address) - except OSError: - if os.path.exists(local_socket_address): - raise - cmd_socket = socket(AF_UNIX) - cmd_socket.bind(local_socket_address) + cmd_socket = socket.socket(AF_INET, SOCK_STREAM) + cmd_socket.bind((HOST, SOCKET_PORT)) cmd_socket.listen(5) while not is_exiting.isSet(): logging.debug("accepting") @@ -142,6 +139,7 @@ def cmd_shutdown(): cmd_socket.close() socket(AF_UNIX).connect(local_socket_address) cmd.join() + class AJAXHandler(RequestHandler): @gen.coroutine def get(self): |