示例#1
0
 internal void SendENet(byte[] enetPacket)
 {
     byte[] data = new byte[ENetCommand.PROTOCOL_HEADER.Size() + enetPacket.Length];
     ENetProtocolHeader header = new ENetProtocolHeader { PeerID = Util.ToNetOrder(OutgoingPeerID), SentTime = Util.ToNetOrder(Util.Timestamp()) };
     var handle = GCHandle.Alloc(data, GCHandleType.Pinned);
     Marshal.StructureToPtr(header, handle.AddrOfPinnedObject(), false);
     handle.Free();
     Buffer.BlockCopy(enetPacket, 0, data, ENetCommand.PROTOCOL_HEADER.Size(), enetPacket.Length);
     SendRaw(data);
 }
示例#2
0
 internal void SendAcks()
 {
     if(State == ENetPeerState.Disconnected || State == ENetPeerState.Zombie) return;
     ENetProtocolAcknowledge ack;
     int headerSize = sizeof(ENetProtocolHeader);
     int ackSize = ENetCommand.ACKNOWLEDGE.Size();
     byte[] data = new byte[headerSize + (PendingAcks.Count * ackSize)];
     var handle = GCHandle.Alloc(data, GCHandleType.Pinned);
     var currentLoc = handle.AddrOfPinnedObject() + headerSize;
     while (PendingAcks.TryDequeue(out ack))
     {
         Marshal.StructureToPtr(ack, currentLoc, false);
         currentLoc += ackSize;
     }
     ENetProtocolHeader header = new ENetProtocolHeader { PeerID = Util.ToNetOrder(OutgoingPeerID), SentTime = Util.ToNetOrder(Util.Timestamp()) };
     Marshal.StructureToPtr(header, handle.AddrOfPinnedObject(), false);
     handle.Free();
     SendRaw(data);
 }