|
Network Library Documentation
|
Main MonoBehaviour singleton class handling the client-side networking logic (TCP, UDP) in Unity. More...
Classes | |
| class | TCP |
| Handles TCP connection. More... | |
| class | UDP |
| Handles UDP connection and communication for the client. More... | |
Public Member Functions | |
| bool | IsLocal (int checkId) |
| Checks if the specified ID belongs to this local client. | |
| void | SetToken (string token) |
| Sets the authentication token. | |
| string | GetToken () |
| Gets the authentication token. | |
| byte[] | GetHmacKey () |
| Gets the HMAC key used for secure communication. | |
| void | SetHmacKey (byte[] newHmacKey) |
| Sets the HMAC key for secure communication. | |
| string | GetUsername () |
| Gets the current username. | |
| void | SetUsername (string newUsername) |
| Sets the current username. | |
| int | GetId () |
| Gets the current client ID. | |
| void | SetId (int newId) |
| Sets the client ID. | |
| DefaultNetworkSettings | GetDefaultSettings () |
| Gets default network settings used for connection. | |
| void | ConnectToServer () |
| Starts the connection process to the server. | |
| void | Disconnect () |
| Disconnects the client from the server. | |
| void | ResetNetwork () |
| Resets client network components and reloads the initial scene. | |
| void | MeassureRequest (int pcktId) |
| Sends a ping measurement request to the server. | |
| void | MeassureAnswer (int pcktId) |
| Handles the server’s ping reply and triggers the ping event. | |
| void | DisconnectRequested () |
| Sends a disconnect request to the server. | |
| void | DisconnectOther (int clientid) |
| Disconnects another user with the given ID from the scene. | |
| void | MessageToUserRequest (string message, int clientId) |
| Sends a message to a specific user. | |
| void | MessageToAllRequest (string message) |
| Sends a message to all users in the session. | |
| void | SpawnUserPrefab (int id, string username) |
| Spawns the user prefab locally or remotely. | |
| void | ReceivedMessage (string message) |
| Triggers message-received event with the given message. | |
| void | UpdateTransform (Transform objectTransform) |
| Sends current transform of a game object to the server. | |
| void | ChangeTransform (int id, Vector3 pos, Quaternion rot) |
| Updates the transform of a remote player. | |
| void | AnimationUpdate (int type, string name, float value) |
| Sends animation update to the server. | |
| void | ChangeAnimatorState (int id, int type, string name, float value) |
| Applies received animation state from the server. | |
| void | BandwidthRequest (byte[] data) |
| Sends request to measure bandwidth to the server. | |
| void | SendThroughputData (int pcktId, byte[] data) |
| Sends a packet of data to test throughput. | |
| void | ReceivedBandwidth () |
| Called when bandwidth reply is received from the server. | |
| void | ReceivedThroughput (int pcktId, int dataSize) |
| Called when throughput test result is received. | |
Static Public Member Functions | |
| static void | PacketAction (int packetId, Packet packet) |
| Handles the received packet by type by calling methods in ClientReceiveHandler. | |
Public Attributes | |
| TCP | tcp |
| Handles TCP communication with the server. | |
| UDP | udp |
| Handles UDP communication with the server. | |
| bool | isConnected = false |
| Indicates whether the client is currently connected to the server. | |
Static Public Attributes | |
| static Client | instance |
| Singleton instance of the client. | |
Events | |
| Action | OnConnected |
| Event triggered when the client successfully connects to the server. | |
| Action< string > | OnConnectionFailed |
| Event triggered when the client fails to connect, providing an error message. | |
| Action | OnDisconnected |
| Event triggered when the client is disconnected from the server. | |
| Action< string > | OnMessageReceived |
| Event triggered when a text message is received from the server. | |
| Action< int, Vector3, Quaternion > | OnTransformReceived |
| Event triggered when a transform update is received. | |
| Action< int, int, string, float > | OnAnimationChangeReceived |
| Event triggered when an animation update is received. | |
| Action< int > | OnPingReply |
| Event triggered when a ping response is received. | |
| Action | OnBandwidthReply |
| Event triggered when the bandwidth test result is received. | |
| Action< int, int > | OnThroughputReply |
| Event triggered when throughput test results are received. | |
Private Member Functions | |
| void | Awake () |
| Ensures only one instance of the client exists (Singleton pattern). | |
| void | OnApplicationQuit () |
| Disconnects the client when the application quits. | |
| void | SetClient () |
| Initializes TCP and UDP communication handlers for this client. | |
Private Attributes | |
| DefaultNetworkSettings | defaultNetworkSettings |
| Network settings shared between client and server (IP, port, security, ...). | |
| ClientSettings | ClientSettings |
| Client-specific configuration used during runtime. | |
| int | id = 0 |
| The unique client id assigned by the server. | |
| string | username = "" |
| The current username of the client. | |
| Coroutine | latencyMeassure |
| Reference to the coroutine responsible for measuring latency. | |
| byte[] | hmacKey |
| HMAC key used for message authentication. | |
| string | authToken |
| Authentication token used to verify client identity. | |
Static Private Attributes | |
| static int | DefaultBufferSize = 4096 |
| Default buffer size used for sending and receiving data (in bytes). | |
| void Client.AnimationUpdate | ( | int | type, |
| string | name, | ||
| float | value ) |
|
private |
| void Client.BandwidthRequest | ( | byte[] | data | ) |
| void Client.ChangeAnimatorState | ( | int | id, |
| int | type, | ||
| string | name, | ||
| float | value ) |
| void Client.ChangeTransform | ( | int | id, |
| Vector3 | pos, | ||
| Quaternion | rot ) |
| void Client.ConnectToServer | ( | ) |
Starts the connection process to the server.
Definition at line 283 of file Client.cs.
| void Client.Disconnect | ( | ) |
Disconnects the client from the server.
Definition at line 555 of file Client.cs.
| void Client.DisconnectOther | ( | int | clientid | ) |
| void Client.DisconnectRequested | ( | ) |
Sends a disconnect request to the server.
| DefaultNetworkSettings Client.GetDefaultSettings | ( | ) |
Gets default network settings used for connection.
Definition at line 185 of file Client.cs.
| byte[] Client.GetHmacKey | ( | ) |
| int Client.GetId | ( | ) |
| string Client.GetToken | ( | ) |
Gets the authentication token.
Definition at line 136 of file Client.cs.
| string Client.GetUsername | ( | ) |
| bool Client.IsLocal | ( | int | checkId | ) |
| void Client.MeassureAnswer | ( | int | pcktId | ) |
| void Client.MeassureRequest | ( | int | pcktId | ) |
Sends a ping measurement request to the server.
| void Client.MessageToAllRequest | ( | string | message | ) |
| void Client.MessageToUserRequest | ( | string | message, |
| int | clientId ) |
|
private |
Disconnects the client when the application quits.
|
static |
Handles the received packet by type by calling methods in ClientReceiveHandler.
Definition at line 215 of file Client.cs.
| void Client.ReceivedBandwidth | ( | ) |
| void Client.ReceivedMessage | ( | string | message | ) |
| void Client.ReceivedThroughput | ( | int | pcktId, |
| int | dataSize ) |
| void Client.ResetNetwork | ( | ) |
Resets client network components and reloads the initial scene.
This can be changed.
Definition at line 572 of file Client.cs.
| void Client.SendThroughputData | ( | int | pcktId, |
| byte[] | data ) |
|
private |
| void Client.SetHmacKey | ( | byte[] | newHmacKey | ) |
| void Client.SetId | ( | int | newId | ) |
| void Client.SetToken | ( | string | token | ) |
| void Client.SetUsername | ( | string | newUsername | ) |
| void Client.SpawnUserPrefab | ( | int | id, |
| string | username ) |
| void Client.UpdateTransform | ( | Transform | objectTransform | ) |
|
private |
|
private |
|
staticprivate |
|
private |
|
private |
|
private |
|
static |
| bool Client.isConnected = false |
|
private |
|
private |
| Action<int,int, string, float> Client.OnAnimationChangeReceived |
| Action Client.OnBandwidthReply |
| Action Client.OnConnected |
| Action<string> Client.OnConnectionFailed |
| Action Client.OnDisconnected |
| Action<string> Client.OnMessageReceived |
| Action<int> Client.OnPingReply |
| Action<int,int> Client.OnThroughputReply |