Network Library Documentation
Loading...
Searching...
No Matches
ClientSendHandler Class Reference

Handles sending various network requests from the client to the server using TCP or UDP. More...

Inheritance diagram for ClientSendHandler:

Static Public Member Functions

static void WelcomeReceived ()
 Sends a response to the server confirming the getting of the welcome packet.
static void MeassureRequest (int pcktId)
 Sends a UDP latency packet to the server.
static void DisconnectRequest ()
 Sends a disconnect request to the server. Includes an authentication token if enabled.
static void MessageToUserRequest (string message, int toSendId)
 Sends a private text message to a specific user by server.
static void MessageToAllRequest (string message)
 Sends a broadcast message to all users by server.
static void SendTransform (int id, Transform objectTransform)
 Sends the updated position and rotation of an object to the server. Uses UDP or TCP depending on the current settings.
static void SendAnimationUpdate (int type, string name, float value)
 Sends an animation parameter update to the server.
static void SendBandwidthRequest (byte[] data)
 Sends a packet with raw data to the server for bandwidth measurement.
static void SendThroughputRequest (int pcktId, byte[] data)
 Sends a UDP packet to the server to test network throughput.

Static Private Member Functions

static void SendTCPData (Packet packet)
 Sends a packet to the server using TCP.
static void SendUDPData (Packet packet)
 Sends a packet to the server using UDP if the client is connected and UDP is initialized.

Detailed Description

Handles sending various network requests from the client to the server using TCP or UDP.

Definition at line 8 of file ClientSendHandler.cs.

Member Function Documentation

◆ DisconnectRequest()

void ClientSendHandler.DisconnectRequest ( )
static

Sends a disconnect request to the server. Includes an authentication token if enabled.

Definition at line 33 of file ClientSendHandler.cs.

34 {
35 Packet newPacket = new Packet((int)Packet.ClientPackets.DisconnectRequest);
36 newPacket.Write(Client.instance.GetId());
37 if (Client.instance.GetDefaultSettings().useAuthentificationTokens == true)
38 {
39 newPacket.Write(Client.instance.GetToken());
40 }
41 SendTCPData(newPacket);
42 }
static void SendTCPData(Packet packet)
Sends a packet to the server using TCP.
void Write(string text)
Write string data.
Definition Packet.cs:44

◆ MeassureRequest()

void ClientSendHandler.MeassureRequest ( int pcktId)
static

Sends a UDP latency packet to the server.

Definition at line 23 of file ClientSendHandler.cs.

24 {
25 Packet newPacket = new Packet((int)Packet.ClientPackets.MeassureRequest);
26 newPacket.Write(Client.instance.GetId());
27 newPacket.Write(pcktId);
28 SendUDPData(newPacket);
29 }
static void SendUDPData(Packet packet)
Sends a packet to the server using UDP if the client is connected and UDP is initialized.

◆ MessageToAllRequest()

void ClientSendHandler.MessageToAllRequest ( string message)
static

Sends a broadcast message to all users by server.

Definition at line 60 of file ClientSendHandler.cs.

61 {
62 Packet newPacket = new Packet((int)Packet.ClientPackets.MessageToAllRequest);
63 newPacket.Write(Client.instance.GetId());
64 if (Client.instance.GetDefaultSettings().useAuthentificationTokens == true)
65 {
66 newPacket.Write(Client.instance.GetToken());
67 }
68 newPacket.Write(message);
69 SendTCPData(newPacket);
70 }

◆ MessageToUserRequest()

void ClientSendHandler.MessageToUserRequest ( string message,
int toSendId )
static

Sends a private text message to a specific user by server.

Definition at line 46 of file ClientSendHandler.cs.

47 {
48 Packet newPacket = new Packet((int)Packet.ClientPackets.MessageToUserRequest);
49 newPacket.Write(toSendId);
50 if (Client.instance.GetDefaultSettings().useAuthentificationTokens == true)
51 {
52 newPacket.Write(Client.instance.GetToken());
53 }
54 newPacket.Write(message);
55 SendTCPData(newPacket);
56 }

◆ SendAnimationUpdate()

void ClientSendHandler.SendAnimationUpdate ( int type,
string name,
float value )
static

Sends an animation parameter update to the server.

Definition at line 96 of file ClientSendHandler.cs.

97 {
98 Packet packet = new Packet((int)Packet.ClientPackets.AnimationChange);
99 packet.Write(Client.instance.GetId());
100 if (Client.instance.GetDefaultSettings().useAuthentificationTokens == true)
101 {
102 packet.Write(Client.instance.GetToken());
103 }
104 packet.Write(type); // 0=bool, 1=float, 2=trigger
105 packet.Write(name);
106 if (type != 2) packet.Write(value);
107 SendTCPData(packet);
108 }

◆ SendBandwidthRequest()

void ClientSendHandler.SendBandwidthRequest ( byte[] data)
static

Sends a packet with raw data to the server for bandwidth measurement.

Definition at line 112 of file ClientSendHandler.cs.

113 {
114 Packet packet = new Packet((int)Packet.ClientPackets.BandwidthRequest);
115 packet.Write(Client.instance.GetId());
116 if (Client.instance.GetDefaultSettings().useAuthentificationTokens == true)
117 {
118 packet.Write(Client.instance.GetToken());
119 }
120 packet.Write(data.Length);
121 packet.Write(data);
122 SendTCPData(packet);
123 }

◆ SendTCPData()

void ClientSendHandler.SendTCPData ( Packet packet)
staticprivate

Sends a packet to the server using TCP.

Definition at line 140 of file ClientSendHandler.cs.

141 {
142 packet.SizeOfDataAtStart();
143 Client.instance.tcp.Send(packet);
144 }
void SizeOfDataAtStart()
Definition Packet.cs:296

◆ SendThroughputRequest()

void ClientSendHandler.SendThroughputRequest ( int pcktId,
byte[] data )
static

Sends a UDP packet to the server to test network throughput.

Definition at line 127 of file ClientSendHandler.cs.

128 {
129 Packet packet = new Packet((int)Packet.ClientPackets.ThroughputRequest);
130 packet.Write(Client.instance.GetId());
131 packet.Write(pcktId);
132 packet.Write(data.Length);
133 packet.Write(data);
134 SendUDPData(packet);
135 }

◆ SendTransform()

void ClientSendHandler.SendTransform ( int id,
Transform objectTransform )
static

Sends the updated position and rotation of an object to the server. Uses UDP or TCP depending on the current settings.

Definition at line 75 of file ClientSendHandler.cs.

76 {
77 Packet newPacket = new Packet((int)Packet.ClientPackets.TransformChange);
78 newPacket.Write(id);
79 if (Client.instance.GetDefaultSettings().useAuthentificationTokens == true)
80 {
81 newPacket.Write(Client.instance.GetToken());
82 }
83 newPacket.Write(objectTransform.position);
84 newPacket.Write(objectTransform.rotation);
85 if(Client.instance.GetDefaultSettings().allowUDP == true)
86 {
87 SendUDPData(newPacket);
88 } else
89 {
90 SendTCPData(newPacket);
91 }
92 }

◆ SendUDPData()

void ClientSendHandler.SendUDPData ( Packet packet)
staticprivate

Sends a packet to the server using UDP if the client is connected and UDP is initialized.

Definition at line 148 of file ClientSendHandler.cs.

149 {
150 if (Client.instance == null || !Client.instance.isConnected || Client.instance.udp == null) return;
151 packet.SizeOfDataAtStart();
152 Client.instance.udp.SendUdpData(packet);
153 }

◆ WelcomeReceived()

void ClientSendHandler.WelcomeReceived ( )
static

Sends a response to the server confirming the getting of the welcome packet.

Definition at line 13 of file ClientSendHandler.cs.

14 {
15 Packet newPacket = new Packet((int)Packet.ClientPackets.welcomeReceived);
16 newPacket.Write(Client.instance.GetId());
17 newPacket.Write(Client.instance.GetUsername());
18 SendTCPData(newPacket);
19 }