Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local default = "wss://osmarks.ml/ws/"
- local ws, error, url
- function connect()
- ws, error = http.websocket(url)
- if error then
- print(error)
- else
- print "Connected"
- end
- end
- repeat
- write "URL> "
- url = read()
- if url == "" then
- print("Defaulted to", default)
- url = default
- end
- connect()
- until ws
- function readWS()
- while true do
- print(ws.receive())
- end
- end
- function send(msg)
- local ok = pcall(ws.send, msg)
- if not ok then
- print "Disconnected"
- connect()
- send(msg)
- end
- end
- function writeWS()
- while true do
- sleep(0.2) -- so response can arrive
- write "|> "
- local input = read()
- send(input)
- end
- end
- parallel.waitForAll(writeWS, readWS)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement