diff --git a/lab1/client.py b/lab1/client.py index 162aee2cca4456664a32fbdd8a05b18b06b44b08..7758dad05952080a59c26cf1904e32f2299db5bb 100644 --- a/lab1/client.py +++ b/lab1/client.py @@ -68,19 +68,20 @@ class DatabaseProxy(object): # # Your code here. # - args = [] msg = { "method": "read" , - "args": args + "args": [] } s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect(self.address) - conn = s.makefile(mode="rw") - conn.write(json.dumps(msg) + '\n') - conn.flush() - res = json.loads(conn.readline()) - conn.flush() + worker = s.makefile(mode="rw") + worker.write(json.dumps(msg) + '\n') + worker.flush() + + res = json.loads(worker.readline()) + s.close() + return res pass @@ -94,12 +95,14 @@ class DatabaseProxy(object): } s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect(self.address) - conn = s.makefile(mode="rw") - conn.write(json.dumps(msg) + '\n') - conn.flush() - res = json.loads(conn.readline()) - conn.flush() + worker = s.makefile(mode="rw") + worker.write(json.dumps(msg) + '\n') + worker.flush() + + res = json.loads(worker.readline()) + s.close() + if res: print(res) pass diff --git a/lab1/dbs/fortune.db b/lab1/dbs/fortune.db index 0a814b408b0e5ad7f4c3cd9435b8772d6e4f91a5..9ae637cafaf60179125c5f59ed41641de8f95f84 100644 --- a/lab1/dbs/fortune.db +++ b/lab1/dbs/fortune.db @@ -3017,39 +3017,3 @@ come at you rapidly. "Style Invitational Report from Week 278" published August 2, 1998 % -TDDD25 -% -distributed systems -% -hai -% -hai -% -hai -% -jhj -% -jkjkj -% -nnn -% -jjj -% -hhh -% -jkdhkjhdf -% -iudyucgdhcn -% -ttttttttttttt -% -jjjjjjjjjjj -% -kkkkkkkkk -% -hhhh -% -jj -% -klooo -% diff --git a/lab1/server.py b/lab1/server.py index 1fe432ac4ad64af627484f98fc1c63603316c736..364881582d2cbdac64c9b656604c34c4ccb9b1b1 100644 --- a/lab1/server.py +++ b/lab1/server.py @@ -129,16 +129,23 @@ class Request(threading.Thread): # request_message = json.loads(request) + try: + #print(request_message) if request_message != None and request_message['method'] != None and request_message['args'] != None: + if request_message['method'] == "write" and len(request_message['args']) > 0: + res = json.dumps(self.db_server.write(request_message['args'])) elif request_message['method'] == "read": res = json.dumps(self.db_server.read()) + except Exception as e: + else: - res = json.dumps({"error" : {"name": "Unknown method" , "args": request_message['method']}}) + #res = json.dumps({"error" : {"name": "error method" , "args": request_message['method']}}) else: - res = json.dumps({"error" : {"name": "Unknown method" , "args": request_message['method']}}) + #res = json.dumps({"error" : {"name": "error method" , "args": request_message['method']}}) return res + pass def run(self):