WebSocketOverview
WebSocket.connect
Represents creation of a WebSocket connection.
Aliases
websocket.connectwebsocket.ConnectWebSocket.Connectwebsocket.newwebsocket.NewWebSocket.newWebSocket.NewDetails#
Connects to a ws:// or wss:// endpoint and returns a socket with Send, Close, OnMessage and OnClose. Connection establishment can fail. The example requires a local WebSocket echo server on port 8081.
Examples#
Example
local ok, socket = pcall(WebSocket.connect, "ws://127.0.0.1:8081")
if ok then
socket.OnMessage:Connect(function(message) print(message) end)
socket:Send("hello")
task.delay(1, function() socket:Close() end)
else
warn(socket)
end