wrong websocket documentation
Commandcracker opened this issue ยท 0 comments
The documentation for websocketAsync is wrong.
It returns true
or false, error_message: str
http.websocket also seams a bit wrong:
I also found out, when a web-socket server is not responding (creating a ws connection)
then http.websocket will wait about 1min and then cancel the connection.
some way of setting a timeout would be nice like in Websocket.receive
my current workaround / implementation is this:
function websocket_with_timeout(_url, _headers, _timeout)
if http.websocketAsync then
local websocket, websocket_error = http.websocketAsync(_url, _headers)
if not websocket then
return false, websocket_error
end
local timerID = os.startTimer(_timeout)
while true do
local event, param1, param2 = os.pullEvent()
-- TODO: Close web-socket when the connection succeeds after the timeout
if event == "websocket_success" and param1 == _url then
return param2
elseif event == "websocket_failure" and param1 == _url then
return false, param2
elseif event == "timer" and param1 == timerID then
return false, "Timeout"
end
end
end
-- use websocket without timeout
-- when the CC version dos not support websocketAsync
return http.websocket(_url, _headers)
end