KL0-6 / LuauWebsockets

Lua C api to interact with websockets!

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

LuauWebsockets

LuaU C API to interact with websockets using IXWebSocket!

Example usage:

local socket = Socket.connect("ws://localhost:8008"); -- Connect to the socket

socket.OnMessage = function(message) -- Invoked when a message is received 
    print("New message from socket!", message);
    socket:Send(message)
end

socket.OnClose = function() -- Invoked when the connection is closed
    print("Socket Closed!");
end

socket:Send("Hello from lua"); -- Send a message
socket:Close(); -- Closes the connection

Documentation:

Socket.connect

Connects to url.

Example

local socket = Socket.connect("ws://localhost:8008");

Socket.send

Sends a text message to the socket.

Parameters

  • socket - The socket userdata returned when you connect to a socket.
  • message - The message you want to send

Socket.OnMessage

ℹ️ Callback Optional callback invoked when a new message is received.

Parameters

  • message - The message received

Example

socket.OnMessage = function(message)
    print("New message from socket!", message);
end

Socket.OnClose

ℹ️ Callback Optional callback invoked when the connection is closed.

Example

socket.OnClose = function()
    print("Socket Closed!");
end

About

Lua C api to interact with websockets!

License:MIT License


Languages

Language:C++ 93.1%Language:CMake 6.9%