Skip to main content
Creates two BindableEvents, opens a WebSocket client WebSocket connection to the provided URL, and yields until the connection attempt finishes. On success, it returns a WebSocket table with OnMessage and OnClose events, Send and Close methods supplied by the methods, and an connection state. Incoming message data is fired with OnMessage as a string. When the receive loop ends, OnClose is fired with no arguments. On connection failure, the function raises an error string that starts with “WebSocket connection failed”.

Syntax

Aliases

  • WebSocket.Connect
  • websocket.connect
  • websocket.Connect

Arguments

Returns

Example

Open a WebSocket, listen for messages and close events, then use the socket methods.