change server.py (chnage ip to 0.0.0.0 / add read exception handling / add read/write encoding)
This commit is contained in:
parent
0967c74dc5
commit
834eed3b53
@ -6,7 +6,7 @@ import websockets
|
|||||||
import pprint
|
import pprint
|
||||||
|
|
||||||
#server config <change ip if you like>
|
#server config <change ip if you like>
|
||||||
ip = "127.0.0.1"
|
ip = "0.0.0.0"
|
||||||
port = 8080
|
port = 8080
|
||||||
|
|
||||||
#global vars
|
#global vars
|
||||||
@ -48,18 +48,21 @@ def client_connect(websocket, path):
|
|||||||
print("info>fileop> got read")
|
print("info>fileop> got read")
|
||||||
print("info>fileop>read:" + command[2])
|
print("info>fileop>read:" + command[2])
|
||||||
|
|
||||||
f = open(command[2], "r")
|
try:
|
||||||
content = f.read()
|
f = open(command[2], "r", encoding='utf8')
|
||||||
f.close()
|
content = f.read()
|
||||||
|
f.close()
|
||||||
|
|
||||||
print("reading done")
|
print("reading done")
|
||||||
|
except:
|
||||||
|
print("Error reading file:"+ command[2])
|
||||||
|
|
||||||
#send content
|
#send content
|
||||||
#yield from sendMsg(websocket, "file###" + command[2] + "###" + content)
|
#yield from sendMsg(websocket, "file###" + command[2] + "###" + content)
|
||||||
yield from broadcast("file###" + command[2] + "###" + content);
|
yield from broadcast("file###" + command[2] + "###" + content);
|
||||||
|
|
||||||
elif command[1] == "write":
|
elif command[1] == "write":
|
||||||
f = open(command[2], "w")
|
f = open(command[2], "w", encoding='utf8')
|
||||||
f.write(command[3])
|
f.write(command[3])
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user