WebSocket
Initializing
variant WebSocket.new(string Address)
Creates a new WebSocket object pointing at the given address and returns it. (websocket ssl is currently not supported, and will crash upon attempt to use)
Class Methods
Socket.ConnectToServer
ConnectToServer()
Connects to the server specified when making the websocket object.
Socket.Send
Send(str Message)
Sends the message to the websocket server.
Socket.Close
Close(int code, str Reason)
Closes the websocket connection with the code and reason specified.
Callback Functions
Socket.OnMessage
OnMessage(string Data) [writeonly]
Socket.OnConnect
OnConnect() [writeonly]
Socket.OnClose
OnClose(int Code, string Reason) [writeonly]
Socket.OnFail
OnFail(string Reason) [writeonly]
Example
local ws = WebSocket.new("ws://echo.websocket.org") ws.OnMessage = function(Data) print("received", Data) end ws.OnConnect = function() print("connected") ws:Send("ProtoSmasher rocks!") end ws.OnClose = function(Code, Reason) print("closed, code:", Code, "reason:", Reason) end ws.OnFail = function(Reason) print("failed to connect, reason:", Reason) end ws:ConnectToServer() wait(2) ws:Close(1000, "normal close")
Expected Output for the above example: