/// <summary> /// Attempts to send a packet to the server. /// </summary> /// <returns>If the packet was sent or not.</returns> /// <param name="packet">The packet to send</param> public Boolean SendPacket(Packet packet) { if (packet.GetFullData().Length == 0) { Console.Error.WriteLine("Cannot send a packet with length = 0"); return false; } this.connection.SendPacket(packet); return true; }
/// <summary> /// Sends a packet to the Socket we're connected with. /// </summary> /// <param name="packet">The packet to send</param> public void SendPacket(Packet packet) { lock (SyncSend) { if (Sock.Connected) { try { byte[] data = packet.GetFullData(); Sock.Send(data, data.Length, SocketFlags.None); log.Log(packet, false); if (onPacketSendListeners != null) onPacketSendListeners(packet); } catch (Exception ex) { Show("Unable to sent a packet."); Show(ex); } } else Show("Fail. You shouldn't be able to make it send a packet, without having a connection."); } }
/// <summary> /// Sends a packet to the Socket we're connected with. /// </summary> /// <param name="packet">The packet to send</param> public void SendPacket(Packet packet) { lock (SyncSend) { if (Sock.Connected) { try { byte[] data = packet.GetFullData(); Sock.Send(data, data.Length, SocketFlags.None); packet.timeSent = new TimeSpan(DateTime.UtcNow.Ticks).TotalMilliseconds; log.Log(packet, false); if (onPacketSendListeners != null) onPacketSendListeners(packet); if (confirmPackets) { if (packet.GetHeader() != Headers.PACKET_RECEIVED) this.packetProcessor.SentPacket(packet, this); } // Console.Out.WriteLine("Sent a packet with header " + packet.GetHeader() + " and ID " + packet.GetPacketID()); } catch (Exception ex) { Show("Unable to sent a packet."); Show(ex); } } else Show("Fail. You shouldn't be able to make it send a packet, without having a connection."); } }