Skip to content

grpht/TCPClientPlugin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TCPClientPlugin

TCPClient make easy to connect and comunicate with your server via TCP Socket.
You can easily implement all the functions by learning how to use 4 blueprints.
Because of It is only maden by C++17 and unreal libray, any device that supports multi-threading can be used.

features

  • All features can be created using blueprints.
  • Only c++ can be used for optimization.
  • Connect to the server via TCP Socket
  • Supports multiple connections with various servers.
  • Support type : bool, int8, int16, int32, int64, float, double(c++ only), String(utf-8) and bytes array.
  • Each packet is managed with a Blueprint or C++ Class.
  • Not Polling method. It can save cpu usage.

1. 4 Basic Classes

image

  • TCPClientSubsystem : Subsystem is responsible for creating and destroying sessions. You can get the sessions that you created through this.
  • TCPClientSessionBase : The session manages communication with the connected server.
  • TCPRecvPacketBase : It defines the packets to be received from the server.
  • TCPSendPacketBase : It defines the packets to be sent to the server.

    image

2. How To Use

Step.1 - Defining Session

Expand

1-1) Create Session blueprint in Content Drawer

image

1-2) Open session blueprint, click 'class defaults' and setting session in details pannel

image

  • Session Name : 'SessionName' is required when get the session from Subsystem. So, you must input unique value
  • Ip : IP Address of server. If you check DNS, it will be treated as a DNS Address
  • Port : Port of server
  • Custom Header : You can set a custom header. If set to None, the default settings will be applied.
  • packet to Receive : Register your created RecvPacket. This will enable you to convert and respond to the byte messages received from the server.

1-3) Override 'OnRecvPacket' in Event Graph and divide it by PacketId and handle it appropriately

image

Step.2 Defining RecvPacket

Expand

2-1) Create 'RecvPacket' Blueprint in Content Drawer

image
image

2-2) Open blueprint, and set 'Packet Id' on details pannel

image

  • The session converts to the RecvPacket that matches this Id

2-3) Add variable as you want

image

2-4) Override 'Desereialize' function, This defines how to convert the byte message received from the server.

image

2-5) Open the session and register this packet on details pannel

image

Step.3 Defining SendPacket

Expand

3-1) Create 'SendPacket' Blueprint in Content Drawer

image
image

3-2) Open blueprint, you can set 'Packet Id' on details panel.

image

  • This is the Id of the packet you will send, and it will be included in the header

3-3) Add variables as you want

image

3-4) Override 'Serialize' function. it defines how to convert the message into bytes.

image
image

3-5) Use it in other blueprint

image

  • You can use 'CreateSendPacket' method to instantiate SendPacket, and set member after casting it.
  • Call 'SendPacket' method of Session. Then packet is sended to server that relative with session

Step.4 Connecting Session

Expand

4-1) Call 'ConnectSession' in TCPClientSubsystem, and set the session to the one you have created.

image

4-2) Through the Connected Delegate, ensure that the next steps can be taken upon connection.

image

  • The same applies to the Disconnected Delegate.

Step.5 Get Session

Expand

5-1) Now, you can obtain the session connected to the server anytime and anywhere through the TCPClientSubsystem's 'GetSession' method.

image

  • Communicate with the server through this connected session

5-2) If you need to obtain a session whose connection status is uncertain, use the 'GetSessionLazy' method

image

3. Life Cycle of Session

image

4. Policy

4-1. Default Header Policy

packetPolicy
Inherit from TCPHeaderComponent.h to configure a header suitable for your server environment.
Refer to the comments in the code for more details.

4-2. String Policy

1) Length-Prefixed method for Write strings. (WriteStringUTF8)

Serialize the 2-byte number representing the byte length of the string, followed by the string itself.
stringPolicy

2) Raw bytes of string (WriteStringUTF8Raw)

image

3) Null-Terminated method for Write strings. (WriteStringUTF8NT)

null character at the end of the string.
image

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •