/// <summary> /// Enqueues a packet for sending. /// </summary> /// <param name="channelID">The ID of the channel to send on.</param> /// <param name="packet">The packet to send.</param> /// <returns>True if the packet was enqueued successfully, or false if an error occured.</returns> /// <exception cref="InvalidOperationException">The peer is not initialized.</exception> /// <exception cref="ENetException">An error occured.</exception> public void Send(byte channelID, Packet packet) { CheckInitialized(); packet.CheckInitialized(); int ret = ENetApi.enet_peer_send(NativeData, channelID, packet.NativeData); if (ret < 0) { throw new ENetException("An error occured sending to the peer."); } }
/// <summary> /// Broadcast a packet to all peers. /// </summary> /// <param name="channelID">The ID of the channel</param> /// <param name="packet">The packet to send.</param> /// <remarks>ENet takes ownership of the packet. Do not call methods on it afterwards.</remarks> /// <exception cref="InvalidOperationException">The host is not initialized.</exception> public void Broadcast(byte channelID, ref Packet packet) { CheckInitialized(); packet.CheckInitialized(); bool clear = packet.ReferenceCount == 0; ENetApi.enet_host_broadcast(NativeData, channelID, packet.NativeData); if (clear) { packet.NativeData = null; } // Broadcast may automatically free in this case. }