Unreal Engine Plugin
Websocket Server
WebSocket server for Unreal Engine: Blueprint nodes, events and C++ usage with the Internet Protocol plugin.
References
#include "websocket/wsserver.h"
How to use
Blueprint: search by GetInternetProtocolSubsystem and call CreateWebsocketServer function
C++: Use the code bellow
#include "websocket/wsserver.h"
UWSServer* net = NewObject<UWSServer>();Variables
Backlog
- Set/Get the maximum number of simultaneous client connections the server will accept in queue.
Backlog
Use Tls
- New in 4.0. Encrypts the connection with TLS. With no
Set Tls Optionscall, the secure default options are used. - Applies to the next connection.
Use Tls
Sub Protocols
- New in 4.0. Subprotocols supported, in order of preference. The first one the client offers is selected.
Sub Protocols
Ping Interval Seconds
- New in 4.0. Remotes send a Ping after this much silence. Default
20,0= never.
Ping Interval Seconds
Idle Timeout Seconds
- New in 4.0. Remotes are closed (
Operation timed out) after this much time without any frame from the client. Default60,0= never.
Idle Timeout Seconds
Functions
Is Open
- Return true if socket is open.
Is Open
Return Value
Local Endpoint
- Get the local endpoint of the socket. Use this function only after open connection.
Local Endpoint
Return Value
Clients
- Returns a copy of the set of clients connected to the server (a reference before 4.0).
- A client stays in the set until its own
On Closearrives.
Clients
Return Value
Get Error Code
- Return a struct of the latest error code returned by asio.
Get Error Code
Return Value
Open
- Opens the TCP server and starts listening for incoming connections.
- It returns false if socket is already open or if asio return any error code during the bind.
Addressmust be an IP literal,localhostor empty (any address). Host names are not resolved: they, and ports outside 0-65535, fail with anInvalid argumenterror.
OpenTarget is WSServer
Target
Bind Opts
Return Value
Close
- Close the underlying socket and stop listening for data on it. 'on_close' event will be triggered.
CloseTarget is WSServer
Target
Set Tls Options
- New in 4.0. Turns TLS on with these options. See Security Context Options.
- A TLS server needs a certificate and a private key.
- Applies to the next connection.
Set Tls OptionsTarget is WSServer
Target
Sec Opts
Events
On Listening
- This event will be triggered when socket start to listening.
Bind Event to On Listening
Target
Event
On ListeningCustom Event
On Client Accepted
- This event will be triggered when new client connect.
Bind Event to On Client Accepted
Target
Event
On Client AcceptedCustom Event
Client
On Close
- Event triggered when socket is closed.
Bind Event to On Close
Target
Event
On CloseCustom Event
On Error
- Event triggered if any error occur during async process.
Bind Event to On Error
Target
Event
On ErrorCustom Event
Error Code
On Upgrade Request
- New in 4.0. When bound, every valid upgrade request waits for your decision: call
Accept UpgradeorReject UpgradeonClient, for example after checking theOriginheader or a token inRequest. - Requests left unanswered are dropped after
Handshake Timeout Seconds. - When not bound, every valid request is accepted automatically.
- A client asking for a wrong
Sec-WebSocket-Versiongets426.
Bind Event to On Upgrade Request
Target
Event
On Upgrade RequestCustom Event
Client
Request
Remote
Each client connected to the server is a WS Remote (UWSRemote), given by On Client Accepted, On Upgrade Request and Clients. In 4.0 the TLS server gives the same class: WSRemoteSsl was merged into it.
Accept Upgrade
- New in 4.0. Accepts the upgrade request received in
On Upgrade Request.
Accept UpgradeTarget is WSRemote
Target
Reject Upgrade
- New in 4.0. Refuses the upgrade request with an HTTP status (for example
401or403) and a reason, then closes the connection.
Reject UpgradeTarget is WSRemote
Target
Status
Reason
Is Open
- Return true if the connection is open.
Is Open
Return Value
Local Endpoint
- Local endpoint of the connection.
Local Endpoint
Return Value
Remote Endpoint
- Address and port of the client.
Remote Endpoint
Return Value
Get Error Code
- Return a struct of the latest error code.
Get Error Code
Return Value
Get Sub Protocol
- New in 4.0. Subprotocol agreed in the handshake (empty: none).
Get Sub Protocol
Return Value
Get Round Trip Time Ms
- New in 4.0. Round trip of the last Ping answered by a Pong, in ms (
-1: none yet).
Get Round Trip Time Ms
Return Value
Get Stats
- New in 4.0. Traffic counters of the current connection: bytes and messages sent and received, queued bytes and the last ping round trip. See Connection Stats.
Get Stats
Return Value
Write
- Sends a text message to the client.
- It returns false if the connection is closed or if the send queue limit is exceeded.
- Write with
Dataframe.Fin = falseto send a fragment. See Dataframe.
WriteTarget is WSRemote
Target
Message
Dataframe
Callback
Return Value
Write Buffer
- Sends a binary message to the client. Same rules as
Write.
Write BufferTarget is WSRemote
Target
Buffer
Dataframe
Callback
Return Value
Ping
- Sends a ping.
PingTarget is WSRemote
Target
Callback
Return Value
Pong
- Sends a pong.
PongTarget is WSRemote
Target
Callback
Return Value
End
- Closing handshake: sends a Close frame with
CodeandReasonand waits up to 5 seconds for the client's Close frame.
EndTarget is WSRemote
Target
Code
Reason
Close
- Closes the connection immediately, without the closing handshake.
CloseTarget is WSRemote
Target
Code
Reason
Remote Events
On Connected
- The WebSocket upgrade completed.
Handshakeis the client request.
Bind Event to On Connected
Target
Event
On ConnectedCustom Event
Handshake
On Unexpected Handshake
- The upgrade request was invalid.
Bind Event to On Unexpected Handshake
Target
Event
On Unexpected HandshakeCustom Event
Handshake
On Message
- A complete message was received.
Bind Event to On Message
Target
Event
On MessageCustom Event
Buffer
Is Binary
On Ping
- A ping was received. A pong is sent back automatically.
Bind Event to On Ping
Target
Event
On PingCustom Event
On Pong
- A pong was received.
Bind Event to On Pong
Target
Event
On PongCustom Event
On Close
- The connection was closed. Fires exactly once, with the close code and reason.
Bind Event to On Close
Target
Event
On CloseCustom Event
Code
Reason
On Error
- An error happened on this connection.
Bind Event to On Error
Target
Event
On ErrorCustom Event
Error Code