tarnet
  • Documentation
    • Introduction
    • Installation
    • How to Use
      • Configurations
        • SocketConfig
        • MessageConfig
        • ClientValidationConfig
      • SocketBuilder
        • SetSocketConfig
        • SetMessageConfig
        • SetClientValidationConfig
        • BuildServer
        • BuildClient
      • ISocketServer
        • Start
        • Stop
        • SendMessageAsync
      • ISocketClient
        • Connect
        • Disconnect
        • SendMessageAsync
      • IServerConnectionsProvider
        • GetConnectedClients
        • GetConnectionUsageRate
  • Logs
    • Change Log
      • v1.0.3
      • v1.0.2
      • v1.0.1
Powered by GitBook
On this page
  1. Documentation
  2. How to Use
  3. Configurations

SocketConfig

PreviousConfigurationsNextMessageConfig

Last updated 5 months ago

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: Use 127.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

  1. Through the Unity Editor Navigate to Assets > Create > Tarnet > SocketConfig to create a SocketConfig instance.

  1. 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 with SocketBuilder, 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.