Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local myURL = "wss://team-david-gaither-david-gaither-1e5fac37.flowfuse.cloud/public/websocks"
- local ws = http.websocket(myURL)
- local comptuerID = os.getComputerID
- local data = {}
- ws.send("Program Start-")
- function reconnect()
- ws = http.websocket(myURL)
- repeat
- data = {os.pullEvent()}
- until data[1] == "websocket_failure" or data[1] == "websocket_message"
- end
- if data[1] == "websocket_failure" then
- print("connection failed, waiting 30 seconds")
- sleep(30)
- return false
- elseif data[1] == "websocket_message" then
- print("reconnected")
- return data[3]
- end
- function sendMsg(msg)
- ws.send(msg)
- end
- function waitMsg()
- local timer_id = os.startTimer(30)
- print("timer id: " .. timer_id)
- repeat
- waitdata = {os.pullEvent()}
- until waitdata[1] ~= nil
- --print("Received message from " .. tostring(waitdata[1]) .. " with contents " .. tostring(waitdata[2]) .. " with event " .. tostring(waitdata[3]))
- if waitdata[1] == "timer" then ws.send("heartbeat") end --and waitdata[2] == timer_id
- if waitdata[1] == "websocket_failure" then reconnect() end
- if waitdata[1] == "websocket_message" then
- if string.find(tostring(waitdata[2]), "pushScores") then
- rednet.send(1, "pushScores")
- end
- end
- end
- while true do waitMsg() end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement