Ejemplo n.º 1
0
 /// <summary>Sends a packet to the specified endpoint via UDP.</summary>
 /// <param name="_clientEndPoint">The endpoint to send the packet to.</param>
 /// <param name="_packet">The packet to send.</param>
 public static void SendUDPData(IPEndPoint _clientEndPoint, Packet _packet)
 {
     try
     {
         if (_clientEndPoint != null)
         {
             udpListener.BeginSend(_packet.ToArray(), _packet.Length(), _clientEndPoint, null, null);
         }
     }
     catch (Exception _ex)
     {
         Console.WriteLine($"Error sending data to {_clientEndPoint} via UDP: {_ex}");
     }
 }
Ejemplo n.º 2
0
 /// <summary>Sends data to the client via TCP.</summary>
 /// <param name="packet">The packet to send.</param>
 public void SendData(Packet packet)
 {
     try
     {
         if (socket != null)
         {
             stream.BeginWrite(packet.ToArray(), 0, packet.Length(), null, null); // Send data to server
         }
     }
     catch (Exception ex)
     {
         Debug.Log($"Error sending data to server via TCP: {ex}");
     }
 }
Ejemplo n.º 3
0
 public void SendData(Packet p)
 {
     try
     {
         if (socket != null)
         {
             stream.BeginWrite(p.ToArray(), 0, p.Length(), null, null);
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine($"Error sending data to player {id} via TCP: {ex}");
     }
 }
Ejemplo n.º 4
0
 public void SendData(Packet packet)
 {
     try
     {
         if (socket != null)
         {
             networkStream.BeginWrite(packet.ToArray(), 0, packet.Length(), null, null);
         }
     }
     catch (Exception e)
     {
         Console.WriteLine($"Error has happened on sending data to client {id}!");
         Console.WriteLine(e.ToString());
     }
 }
Ejemplo n.º 5
0
 /// <summary>Sends data to the client via UDP.</summary>
 /// <param name="packet">The packet to send.</param>
 public void SendData(Packet packet)
 {
     try
     {
         packet.InsertInt(instance.myId); // Insert the client's ID at the start of the packet
         if (socket != null)
         {
             socket.BeginSend(packet.ToArray(), packet.Length(), null, null);
         }
     }
     catch (Exception ex)
     {
         Debug.Log($"Error sending data to server via UDP: {ex}");
     }
 }