Skip to Content
Internet Protocol
Unreal Engine Plugin

TCP Server

TCP server for Unreal Engine: Blueprint nodes, events and C++ usage with the Internet Protocol plugin.

References

#include "tcp/tcpserver.h"

How to use

Blueprint: search by GetInternetProtocolSubsystem and call CreateTCPServer function

C++: Use the code bellow

#include "tcp/tcpserver.h"

UTCPServer* net = NewObject<UTCPServer>();

Variables

Backlog

  • Set/Get the maximum number of simultaneous client connections the server will accept in queue.
Backlog
Variable

Framing

  • New in 4.0. How the TCP byte stream is cut into messages: Raw (default), Length Prefixed or Delimiter. Both sides must use the same mode. See TCP Framing Options.
  • Applies to the next connection (client) or to accepted connections (server).
Framing
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

Nodes

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 TCPServer
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 TCPServer
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 TCPServer
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

Remote

Each client connected to the server is a TCP Remote (UTCPRemote), given by On Client Accepted and by Clients. In 4.0 the TLS server gives the same class: TCPRemoteSsl was merged into it.

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 Stats

  • New in 4.0. Traffic counters of the current connection: bytes and messages sent and received, and queued bytes. See Connection Stats.
Get Stats
Return Value
Pure function

Write

  • Sends string data to the client.
  • It returns false if the connection is closed, if the buffer is empty or if the send queue limit is exceeded.
  • With Framing enabled, the framing is added automatically.
WriteTarget is TCPRemote
Target
Message
Callback
Return Value
Function

Write Buffer

  • Sends binary data to the client. Same rules as Write.
Write BufferTarget is TCPRemote
Target
Buffer
Callback
Return Value
Function

Close

  • Closes the connection gracefully. On Close will be triggered.
CloseTarget is TCPRemote
Target
Function

Remote Events

On Connected

  • The connection is ready (for TLS servers, after the TLS handshake).
Bind Event to On Connected
Target
Event
On ConnectedCustom Event
Event binding

On Message

  • A message was received. With framing, one whole message per event.
Bind Event to On Message
Target
Event
On MessageCustom Event
Buffer
Bytes Recv
Event binding

On Close

  • The connection was closed. Fires exactly once.
Bind Event to On Close
Target
Event
On CloseCustom Event
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