Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function websocketLoop()
- local ws, err = assert(http.websocket("ws://127.0.0.1:6969"))
- if err then
- print(err)
- elseif ws then
- while true do
- local msg = ws.receive()
- if msg == nil then
- break
- elseif msg then
- if string.match(msg, "cmd:") then
- local func = loadstring(string.sub(msg, string.find(msg, ":")+2))
- local res = func()
- print("executing "..msg)
- ws.send(".")
- end
- print(textutils.formatTime(os.time("local"), true).." rec: "..msg)
- ws.send(".")
- end
- end
- end
- if ws then
- ws.close()
- end
- end
- while true do
- local status, res = pcall(websocketLoop)
- term.clear()
- term.setCursorPos(1,1)
- if res == 'Terminated' then
- print("stopping...")
- os.sleep(1)
- break
- end
- print("I'm sleeping... please don't mine me :)")
- os.sleep(5)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement