SocketConfig
SocketConfig
is a ScriptableObject
class used to configure network connections in Tarnet. It allows defining critical network settings such as the IP address, port number, and server capacity. SocketConfig
can be created via the Unity Editor or dynamically at runtime using ScriptableObject.CreateInstance
.
Properties
ipAddress
Description: The IP address the socket will bind to or connect to. Default Value:127.0.0.1
Usage: Use127.0.0.1
for local connections or specify a valid IP address for external connections.port
Description: The port number used for the socket connection. Default Value:5555
Usage: Ensure the port is not already in use by another application.serverCapacity
Description: The maximum number of clients the server can handle simultaneously. Default Value:10
Usage: Adjust this based on the requirements of your project. For high traffic, increase this value as needed.
How to Create SocketConfig
Through the Unity Editor Navigate to Assets > Create > Tarnet > SocketConfig to create a
SocketConfig
instance.

Through Code
SocketConfig config = ScriptableObject.CreateInstance<SocketConfig>();
config.ipAddress = "127.0.0.1";
config.port = 12345;
config.serverCapacity = 100;
Usages:
SocketConfig
is used with Tarnet's SocketBuilder
class via the SetSocketConfig
method, enabling centralized management of all network settings:
SocketBuilder socketBuilder = new SocketBuilder();
socketBuilder.SetSocketConfig(config);
Technical Details
Flexibility:
SocketConfig
integrates seamlessly withSocketBuilder
, offering a centralized configuration system that simplifies network management.Dynamic Usage: The configuration object can be created and customized dynamically in code, providing flexibility during development.
This structure provides a reusable system for different projects, significantly simplifying the management of network configurations.
Last updated