/// <summary> /// Sends a packet to every active connection. /// </summary> /// <param name="packet">Object containing the packet's unique information</param> public void BroadcastPacket(Packet packet) { foreach (var connection in _connections) { if (connection != null) this.SendPacket(packet, connection.Socket); } }
public void SendPacket(Packet packet) { _nettyServer.SendPacket(packet, _socket); }
internal void SendPacket(Packet packet, Socket socket) { this.SendPacket(socket, packet); }
/// <summary> /// Sends a packet to the designated remote socket connnection. /// </summary> /// <param name="packet">Object containing the packet's unique information</param> /// <param name="this.SocketIndex">Socket ID of the desired remote socket that the packet will be sent to.</param> /// <param name="forceSend">Force the current Message Buffer to be sent and flushed.</param> public void SendPacket(Packet packet, int socketIndex) { this.SendPacket(packet, this.GetConnection(socketIndex).Socket); }
/// <summary> /// Registeres a packet for later use. /// </summary> /// <param name="packet">Packet to be registered.</param> private void RegisterPacket(Packet packet) { // Output the details of the packet that we're registering. Console.WriteLine("Registering packet: " + packet.PacketID); // Add this new packet instance to our registered packets list (_registeredPackets). _registeredPackets.Add(packet); }
protected void SendPacket(Socket socket, Packet packet) { try { var dataBuffer = new DataBuffer(); dataBuffer.WriteInteger(packet.PacketID); dataBuffer.WriteBytes(packet.DataBuffer.ReadBytes()); byte[] data = dataBuffer.ReadBytes(); byte[] packetHeader = BitConverter.GetBytes(data.Length); int sent = socket.Send(packetHeader); while (sent < packetHeader.Length) sent += socket.Send(packetHeader, sent, packetHeader.Length - sent, SocketFlags.None); sent = socket.Send(data); while (sent < data.Length) sent += socket.Send(data, sent, data.Length - sent, SocketFlags.None); } catch (NullReferenceException) { } catch (SocketException) { } catch (ObjectDisposedException) { } }