websocket_failure event

Fired when a websocket requested with http.websocketAsync cannot connect.

ExampleAttempt to open a websocket and wait for it to fail.
Attempts to start a connection to an invalid location prints an error when it fails.
Code
<nowiki>
local wsUrl = "wss://echo.websocket.org/404"
local ok, err = http.websocketAsync(wsUrl)
if ok then
  while true do
    -- Wait for a websocket_success or websocket_failure event
    -- matching the desired URL
    local event, url, res = os.pullEvent(url)
    if event == "websocket_success" and url == wsUrl then
      print("Connected")
      break
    elseif event == "websocket_failure" and url == wsUrl then
    printError("Could not connect")
    break
    end
  end
end
    </nowiki>
websocket_failure
Event
Returns
  • url : string The URL of the websocket
  • reason : string The reason the websocket connection could not be started.

Source CC:Tweaked
This article is issued from Computercraft. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.