-
Notifications
You must be signed in to change notification settings - Fork 0
/
advremote.lua
50 lines (45 loc) · 1.31 KB
/
advremote.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
local ws = assert(http.websocket("ws://127.0.0.1:5133"))
print("connected to server")
local id
local isrunning = true
function exitcheck()
while true do
local event = os.pullEventRaw("terminate")
if event == "terminate" then
print("Exiting...")
isrunning = false
ws.close()
break
end
end
end
function main()
while isrunning do
print("ready")
local message, error = ws.receive()
if message then
print("Received message:", message)
if message == "ping" then
ws.send("pong")
elseif message == "sendcode" then
local file = io.open("main.lua", "w")
print("waiting for code")
local filedata, error = ws.receive()
file:write(filedata)
file:close()
elseif message == "runcode" then
id = multishell.launch({}, "main.lua")
multishell.setTitle(id, "Code")
multishell.setFocus(id)
elseif message == "exit" then
print("Exiting...")
break
end
else
print("WebSocket error:", error)
break
end
end
end
parallel.waitForAny(exitcheck, main)
print("Exited")