[Experimental] WebSocket Server


#1

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

-- Add a new listener with a string parameter
AddEventHandler("WebSocketServer:onMessage", function(message)
    print("Received message: " .. message)
end)

Send a message to connected WebSocket clients

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

Changelog

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

#2

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


#3

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?


#4

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.


#5

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:


#6

Is it possible to broadcast live-sounds?

or what does it “broadcast” ?


#7

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


#8

It could be nice with live sounds!


#9

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?


#10

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


#11

Fantastic for a mobile application! Time to work.


#12

God Damn! This has YUGE (trump) potential


#13

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


#14

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


#15

Unfortunately, this is beyond the scope of this resource.


#16

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


#17

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