Fix websocket example files

This commit is contained in:
Filip Tibell 2024-10-17 11:27:32 +02:00
parent f89d02a60d
commit ef294f207c
No known key found for this signature in database
2 changed files with 5 additions and 5 deletions

View file

@ -28,8 +28,8 @@ end)
for _ = 1, 5 do for _ = 1, 5 do
local start = os.clock() local start = os.clock()
socket.send(tostring(1)) socket:send(tostring(1))
local response = socket.next() local response = socket:next()
local elapsed = os.clock() - start local elapsed = os.clock() - start
print(`Got response '{response}' in {elapsed * 1_000} milliseconds`) print(`Got response '{response}' in {elapsed * 1_000} milliseconds`)
task.wait(1 - elapsed) task.wait(1 - elapsed)
@ -38,7 +38,7 @@ end
-- Everything went well, and we are done with the socket, so we can close it -- Everything went well, and we are done with the socket, so we can close it
print("Closing web socket...") print("Closing web socket...")
socket.close() socket:close()
task.cancel(forceExit) task.cancel(forceExit)
print("Done! 🌙") print("Done! 🌙")

View file

@ -15,9 +15,9 @@ local handle = net.serve(PORT, {
handleWebSocket = function(socket) handleWebSocket = function(socket)
print("Got new web socket connection!") print("Got new web socket connection!")
repeat repeat
local message = socket.next() local message = socket:next()
if message ~= nil then if message ~= nil then
socket.send("Echo - " .. message) socket:send("Echo - " .. message)
end end
until message == nil until message == nil
print("Web socket disconnected.") print("Web socket disconnected.")