From 834eed3b539b22e2316c2f8adea00dd7251bfcde Mon Sep 17 00:00:00 2001 From: Raphael Date: Mon, 28 Mar 2016 00:11:53 +0200 Subject: [PATCH] change server.py (chnage ip to 0.0.0.0 / add read exception handling / add read/write encoding) --- server/server.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/server/server.py b/server/server.py index a6a4aa6..ea4a3c9 100644 --- a/server/server.py +++ b/server/server.py @@ -6,7 +6,7 @@ import websockets import pprint #server config -ip = "127.0.0.1" +ip = "0.0.0.0" port = 8080 #global vars @@ -48,18 +48,21 @@ def client_connect(websocket, path): print("info>fileop> got read") print("info>fileop>read:" + command[2]) - f = open(command[2], "r") - content = f.read() - f.close() + try: + f = open(command[2], "r", encoding='utf8') + content = f.read() + f.close() - print("reading done") + print("reading done") + except: + print("Error reading file:"+ command[2]) #send content #yield from sendMsg(websocket, "file###" + command[2] + "###" + content) yield from broadcast("file###" + command[2] + "###" + content); elif command[1] == "write": - f = open(command[2], "w") + f = open(command[2], "w", encoding='utf8') f.write(command[3]) f.close()