Skip to Content
Internet Protocol
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
Variable

Use Tls

  • New in 4.0. Encrypts the connection with TLS. With no Set Tls Options call, the secure default options are used.
  • Applies to the next connection.
Use Tls
Variable

Sub Protocols

  • New in 4.0. Subprotocols supported, in order of preference. The first one the client offers is selected.
Sub Protocols
Variable

Ping Interval Seconds

  • New in 4.0. Remotes send a Ping after this much silence. Default 20, 0 = never.
Ping Interval Seconds
Variable

Idle Timeout Seconds

  • New in 4.0. Remotes are closed (Operation timed out) after this much time without any frame from the client. Default 60, 0 = never.
Idle Timeout Seconds
Variable

Functions

Is Open

  • Return true if socket is open.
Is Open
Return Value
Pure function

Local Endpoint

  • Get the local endpoint of the socket. Use this function only after open connection.
Local Endpoint
Return Value
Pure function

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 Close arrives.
Clients
Return Value
Pure function

Get Error Code

  • Return a struct of the latest error code returned by asio.
Get Error Code
Return Value
Pure function

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.
  • Address must be an IP literal, localhost or empty (any address). Host names are not resolved: they, and ports outside 0-65535, fail with an Invalid argument error.
OpenTarget is WSServer
Target
Bind Opts
Return Value
Function

Close

  • Close the underlying socket and stop listening for data on it. 'on_close' event will be triggered.
CloseTarget is WSServer
Target
Function

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
Function

Events

On Listening

  • This event will be triggered when socket start to listening.
Bind Event to On Listening
Target
Event
On ListeningCustom Event
Event binding

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
Event binding

On Close

  • Event triggered when socket is closed.
Bind Event to On Close
Target
Event
On CloseCustom Event
Event binding

On Error

  • Event triggered if any error occur during async process.
Bind Event to On Error
Target
Event
On ErrorCustom Event
Error Code
Event binding

On Upgrade Request

  • New in 4.0. When bound, every valid upgrade request waits for your decision: call Accept Upgrade or Reject Upgrade on Client, for example after checking the Origin header or a token in Request.
  • 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-Version gets 426.
Bind Event to On Upgrade Request
Target
Event
On Upgrade RequestCustom Event
Client
Request
Event binding

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
Function

Reject Upgrade

  • New in 4.0. Refuses the upgrade request with an HTTP status (for example 401 or 403) and a reason, then closes the connection.
Reject UpgradeTarget is WSRemote
Target
Status
Reason
Function

Is Open

  • Return true if the connection is open.
Is Open
Return Value
Pure function

Local Endpoint

  • Local endpoint of the connection.
Local Endpoint
Return Value
Pure function

Remote Endpoint

  • Address and port of the client.
Remote Endpoint
Return Value
Pure function

Get Error Code

  • Return a struct of the latest error code.
Get Error Code
Return Value
Pure function

Get Sub Protocol

  • New in 4.0. Subprotocol agreed in the handshake (empty: none).
Get Sub Protocol
Return Value
Pure function

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
Pure function

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
Pure function

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 = false to send a fragment. See Dataframe.
WriteTarget is WSRemote
Target
Message
Dataframe
Callback
Return Value
Function

Write Buffer

  • Sends a binary message to the client. Same rules as Write.
Write BufferTarget is WSRemote
Target
Buffer
Dataframe
Callback
Return Value
Function

Ping

  • Sends a ping.
PingTarget is WSRemote
Target
Callback
Return Value
Function

Pong

  • Sends a pong.
PongTarget is WSRemote
Target
Callback
Return Value
Function

End

  • Closing handshake: sends a Close frame with Code and Reason and waits up to 5 seconds for the client's Close frame.
EndTarget is WSRemote
Target
Code
Reason
Function

Close

  • Closes the connection immediately, without the closing handshake.
CloseTarget is WSRemote
Target
Code
Reason
Function

Remote Events

On Connected

  • The WebSocket upgrade completed. Handshake is the client request.
Bind Event to On Connected
Target
Event
On ConnectedCustom Event
Handshake
Event binding

On Unexpected Handshake

  • The upgrade request was invalid.
Bind Event to On Unexpected Handshake
Target
Event
On Unexpected HandshakeCustom Event
Handshake
Event binding

On Message

  • A complete message was received.
Bind Event to On Message
Target
Event
On MessageCustom Event
Buffer
Is Binary
Event binding

On Ping

  • A ping was received. A pong is sent back automatically.
Bind Event to On Ping
Target
Event
On PingCustom Event
Event binding

On Pong

  • A pong was received.
Bind Event to On Pong
Target
Event
On PongCustom Event
Event binding

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
Event binding

On Error

  • An error happened on this connection.
Bind Event to On Error
Target
Event
On ErrorCustom Event
Error Code
Event binding
Edit on GitHub

On this page