Unreal Engine Plugin
Websocket Client
WebSocket client for Unreal Engine: Blueprint nodes, events and C++ usage with the Internet Protocol plugin.
References
#include "websocket/wsclient.h"
How to use
Blueprint: search by GetInternetProtocolSubsystem and call CreateWebsocketClient function
C++: Use the code bellow
#include "websocket/wsclient.h"
UWSClient* client = NewObject<UWSClient>();Variables
Handshake
- Set/Get handshake headers.
- To offer subprotocols, set the
Sec-WebSocket-Protocolheader (for examplechat, json).Get Sub Protocolreturns the one the server selected. - Since 4.0 extensions cannot be requested (
Sec-WebSocket-Extensions), and a server response that selects an extension or a subprotocol that was not offered is rejected.
Handshake
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
Ping Interval Seconds
- New in 4.0. Sends a Ping after this much silence. Default
20,0= never.
Ping Interval Seconds
Idle Timeout Seconds
- New in 4.0. Closes the connection (
Operation timed out) after this much time without any frame from the server. Default60,0= never.
Idle Timeout Seconds
Auto Reconnect
- New in 4.0. Connects again after an unexpected close, waiting 1, 2, 4... seconds. Never after
CloseorEnd. Defaultfalse. On Closefires for the lost connection, thenOn Connectedagain once reconnected.
Auto Reconnect
Reconnect Max Delay Seconds
- New in 4.0. Upper bound of the wait between reconnection attempts. Default
30.
Reconnect Max Delay 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
Remote Endpoint
- Get the remote endpoint of the socket. Use this function only after open connection.
Remote Endpoint
Return Value
Get Error Code
- Return a struct of the latest error code returned by asio.
Get Error Code
Return Value
Write
- Sends string data on the socket.
- It returns false if socket is closed, if buffer is empty or if the send queue limit is exceeded.
- Fragmented messages: write with
Dataframe.Fin = falseto send a fragment, and finish the message withFin = true. See Dataframe. - Empty messages are allowed since 4.0.
WriteTarget is WSClient
Target
Message
Dataframe
Callback
Return Value
On Message SentCustom Event
Error Code
Bytes Sent
Write Buffer
- Sends buffer data on the socket.
- It returns false if socket is closed, if buffer is empty or if the send queue limit is exceeded.
- Fragmented messages: write with
Dataframe.Fin = falseto send a fragment, and finish the message withFin = true. See Dataframe. - Empty messages are allowed since 4.0.
Write BufferTarget is WSClient
Target
Buffer
Dataframe
Callback
Return Value
On Message SentCustom Event
Error Code
Bytes Sent
Ping
- Send a ping message.
- It returns false if socket is closed, if buffer is empty or if the send queue limit is exceeded.
PingTarget is WSClient
Target
Callback
Return Value
On Message SentCustom Event
Error Code
Bytes Sent
Pong
- Send a pong message.
- It returns false if socket is closed, if buffer is empty or if the send queue limit is exceeded.
PongTarget is WSClient
Target
Callback
Return Value
On Message SentCustom Event
Error Code
Bytes Sent
Connect
- Resolve the address and connect asynchronously.
On Connectedis triggered when the connection is established,On Errorif it fails. - It returns false if the socket is already open or connecting.
ConnectTarget is WSClient
Target
Bind Opts
Return Value
End
- Perform a smooth close of socket following ws protocol (RFC 6455 closing handshake) and stop listening for data on it. 'on_close' event will be triggered.
- Sends a Close frame with
CodeandReason, then waits up to 5 seconds for the peer's Close frame before closing the TCP connection.
EndTarget is WSClient
Target
Code
Reason
Close
- Close the underlying socket immediately, without the closing handshake, and stop listening for data on it. 'on_close' event will be triggered with the given
CodeandReason. - Prefer
Endfor a clean disconnect; useCloseto abort.
CloseTarget is WSClient
Target
Code
Reason
Connect Url
- New in 4.0. Connects to
ws://host[:port]/path?query, orwss://(TLS is chosen from the scheme). The path and query go toHandshake.Path.
Connect UrlTarget is WSClient
Target
Url
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
Set Tls Options
- New in 4.0. Turns TLS on with these options. See Security Context Options.
- The server certificate is verified with these options.
- Applies to the next connection.
Set Tls OptionsTarget is WSClient
Target
Sec Opts
Events
On Connected
- Event triggered when a connection is estabilished.
Bind Event to On Connected
Target
Event
On ConnectedCustom Event
Handshake
On Unexpected Handshake
- Event triggered when the server answers the upgrade request with an invalid handshake (wrong status, missing
Upgradeheaders or a badSec-WebSocket-Accept). The connection is not opened.
Bind Event to On Unexpected Handshake
Target
Event
On Unexpected HandshakeCustom Event
Handshake
On Message
- Event triggered when a complete message is received. Fragmented messages are reassembled before this event fires.
- Text messages are validated as UTF-8; messages larger than 64 MiB close the connection with code
1009.
Bind Event to On Message
Target
Event
On MessageCustom Event
Buffer
Is Binary
On Ping
- This event will be triggered when a ping has been received. A pong is sent back automatically, so you do not need to answer it.
Bind Event to On Ping
Target
Event
On PingCustom Event
On Pong
- This event will be triggered when a pong has been received.
Bind Event to On Pong
Target
Event
On PongCustom Event
On Close
- Event triggered when socket is closed. It fires exactly once per connection.
- Since 4.0 close codes
1012-1014are accepted, and codes that cannot be sent (1005,1006,1015, unregistered) are replaced by1000when you callEndorClose. Codeis the close code received from the peer (1005when it sent none),1006when the connection was lost without a Close frame, or1002/1007/1009when the plugin closed the connection because of a protocol violation, invalid UTF-8 or a message that was too large.
Bind Event to On Close
Target
Event
On CloseCustom Event
Code
Reason
On Error
- Event triggered if any error occur during async process.
Bind Event to On Error
Target
Event
On ErrorCustom Event
Error Code