[Experimental] WebSocket Server

WebSocket Server

This library exposes a simple WebSocket server into FXServer.

Features

  • Async
  • Text messages
  • Authorization header support

Downloads

Configuration

Convars available:

Name Type Default value Description
websocket_debug bool false Defines the verbosity of logs
websocket_host string “127.0.0.1” Defines listening host
websocket_port int 80 Defines listening port
websocket_authorization string “” Defines accepted Authorization header value (auth disabled if empty)

Usage

Add a listener to receive messages

AddEventHandler("WebSocketServer:onMessage", function(message, endpoint)
    print("Received message from " .. endpoint .. ": " .. message)
end)

Add a listener to get new connected remote endpoints

AddEventHandler("WebSocketServer:onConnect", function(endpoint)
    print("New WS remote endpoint: " .. endpoint)
end)

Add a listener to get disconnected remote endpoints

AddEventHandler("WebSocketServer:onDisconnect", function(endpoint)
    print("WS remote endpoint " .. endpoint .. " has been disconnected")
end)

Send a message to connected WebSocket clients

TriggerEvent("WebSocketServer:broadcast", "This message will be broadcasted to all connected webSocket clients.");

Send a message to a specific WebSocket client

TriggerEvent("WebSocketServer:send", "This message will be sent to a specific webSocket client.", someValidAndConnectedRemoteEndpoint);

Changelog

0.3.0

  • Update deniszykov.WebSocketListener to 4.2.2
  • Add onConnect and onDisconnect events
  • Add endpoint parameter to onMessage event
  • Add WebSocketServer:send event handler to send message to specific socket
  • Fix some crashes

0.2.1

  • Performance improvements
  • Async HTTP authorization handler
  • Less dependencies

0.2.0

  • Refactor onMessage event

0.1.0

  • Async
  • Text messages
  • Authorization header support
6 Likes

A photo or a longer description? … I have stayed the same I have no idea what this hahah serves : S

Ok i think i know what it’s for, but how would a broadcast be made to all customers? Could it be done by rcon?

It’s a server resource, I can’t provide any screenshot. :upside_down_face:

It’s up to you to broadcast WebSocket messages if needed. In your server script, add an event handler for WebSocketServer:onMessage and then broadcast received message to clients (you can add TriggerClientEvent("your:clientEvent", message) inside the event handler).
Same thing applies for RCON, if you need a command, add a new RCON command to your resource and trigger what ever you want.

I do not know the truth as it would, but I think it will be useful and will do great things !! Thank you :slight_smile:

Is it possible to broadcast live-sounds?

or what does it “broadcast” ?

Only text (string) messages. No binary messages yet.

It could be nice with live sounds!

Seems like people have no idea what you have created here, so let me be the first to say that this is brilliant! If I understand correctly, does this expose a WebSocket that can be approached by other applications? Or is this just for client server communication?

Thanks!
It’s exactly that, a WebSocket (server) that can be approached by other applications (with “real-time” two-ways communication).

1 Like

Fantastic for a mobile application! Time to work.

God Damn! This has YUGE (trump) potential

A mobile application is at the origin of the creation of this resource :relaxed:

1 Like

Great job so far! Might it be possible to also implement a Websocket Client so that it can connect to an existing server?

Unfortunately, this is beyond the scope of this resource.

Old topic but I am unable to change the port number where do I stick websocket_port

This is normal ?
Thank you for answering me as soon as possible :yum:

Hey, this is awesome. :sunglasses:

Edit: Sent you a pull request.

1 Like

Thanks for the PR! :+1:
I released a new tag.

1 Like