45 lines
933 B
Markdown
45 lines
933 B
Markdown
# Websocket Client for Roblox
|
|
|
|
## Setup
|
|
1. Place the WebSocket and Base64 files in ServerScriptService.
|
|
2. Create a new script in Workspace, or wherever you want.
|
|
3. If you are hosting your own WebSocket server, replace the URL `https://sock.kcadev.org` with your own.
|
|
|
|
## Usage
|
|
```lua
|
|
local ws = require(game.ServerScriptService:WaitForChild("WebSocket"))
|
|
local server = ws({
|
|
url = "wss://echo.websocket.org/",
|
|
onMessage = function(message)
|
|
print("Message received: " .. message)
|
|
end,
|
|
onError = function(error)
|
|
print("Error: " .. error)
|
|
end
|
|
})
|
|
server.sendMessage("Hello World")
|
|
```
|
|
|
|
## Functions
|
|
### ws
|
|
```lua
|
|
local server = ws({
|
|
url = "wss://echo.websocket.org/",
|
|
onMessage = function(message)
|
|
print("Message received: " .. message)
|
|
end,
|
|
onError = function(error)
|
|
print("Error: " .. error)
|
|
end
|
|
})
|
|
```
|
|
|
|
### server.sendMessage
|
|
```lua
|
|
server.sendMessage("Hello World")
|
|
```
|
|
|
|
### server.close
|
|
```lua
|
|
server.close()
|
|
``` |