Skip to content

Instantly share code, notes, and snippets.

@damp11113
Created September 7, 2024 05:07
Show Gist options
  • Save damp11113/86ce4dac05a3d1d8caef2afa894e01c2 to your computer and use it in GitHub Desktop.
Save damp11113/86ce4dac05a3d1d8caef2afa894e01c2 to your computer and use it in GitHub Desktop.
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)
else
print("WebSocket error:", error)
break
end
end
end
parallel.waitForAny(exitcheck, main)
print("Exited")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment