sunc docs
  • sUNC Introduction
  • Closures
    • hookfunction
    • hookmetamethod
    • newcclosure
    • iscclosure
    • islclosure
    • isexecutorclosure
    • clonefunction
    • getfunctionhash
  • Cryptography
    • crypt.base64encode
    • crypt.base64decode
  • Debug
    • debug.getconstants
    • debug.getconstant
    • debug.setconstant
    • debug.getupvalues
    • debug.getupvalue
    • debug.setupvalue
  • debug.getstack
  • debug.setstack
  • debug.getprotos
  • debug.getproto
  • Drawing
    • Drawing.new
      • Drawing Objects
    • cleardrawcache
    • getrenderproperty
    • setrenderproperty
    • isrenderobj
  • Environment
    • getgenv
    • getrenv
    • getgc
    • filtergc
  • Filesystem
    • appendfile
    • writefile
    • readfile
    • listfiles
    • isfile
    • delfile
    • loadfile
    • makefolder
    • isfolder
    • delfolder
    • getcustomasset
  • Instances
    • fireproximityprompt
    • fireclickdetector
    • firetouchinterest
    • getinstances
    • getnilinstances
    • cloneref
    • gethui
    • getcallbackvalue
    • compareinstances
  • Metatables
    • getrawmetatable
    • setrawmetatable
    • setreadonly
    • isreadonly
  • Miscellaneous
    • identifyexecutor
    • request
  • Reflection
    • gethiddenproperty
    • sethiddenproperty
    • setscriptable
    • checkcaller
    • setthreadidentity
    • getthreadidentity
  • Scripts
    • getscriptbytecode
    • getscripthash
    • getscriptclosure
    • getsenv
    • getscripts
    • getrunningscripts
    • getloadedmodules
    • getcallingscript
    • loadstring
  • Signals
    • getconnections
      • The Connection object
    • firesignal
    • replicatesignal
  • Websocket
    • WebSocket.connect
Powered by GitBook
On this page
  • WebSocket
  • Example - OnMessage, Send
  • Example - OnClose, Close
  1. Websocket

WebSocket.connect

WebSocket

The WebSocket class provides a simple interface for sending and receiving data over a WebSocket connection.

Constructor - WebSocket.connect

function WebSocket.connect(url: string): WebSocket

WebSocket Methods

Method
Description

Send(message: string): ()

Sends a message over the WebSocket connection.

Close(): ()

Closes the WebSocket connection.

WebSocket Events

Event
Description

OnMessage(message: string): ()

Triggered when a message is received over the WebSocket connection.

OnClose(): ()

Triggered when the WebSocket connection closes.


Example - WebSocket.connect

local ws = WebSocket.connect("ws://echo.websocket.events")
print(ws) -- Output: WebSocket

Example - OnMessage, Send

local ws = WebSocket.connect("ws://echo.websocket.events")
ws.OnMessage:Connect(function(message)
    print(message)
end)
ws:Send("Hello") -- Output: Hello

Example - OnClose, Close

local ws = WebSocket.connect("ws://echo.websocket.events")
ws.OnClose:Connect(function()
    print("Closed")
end)
ws:Close() -- Output: Closed
Previousreplicatesignal

Last updated 2 months ago