private void PackID(Packer packer, int id) { if (this.nextID < sbyte.MaxValue) { packer.Pack((sbyte)id); } else if (this.nextID < short.MaxValue) { packer.Pack((short)id); } else { packer.Pack(id); } }
protected override void fixMessage(Packer packer, byte[] message) { packer.Pack((byte)Protocol.Unordered); packer.Pack(message); }
private void sendAckMessage(int accnum) { Packer packer = new Packer(5); packer.Pack((byte)(((int)Protocol.Reliable) | ACK_BIT)); packer.Pack(accnum); this.connection.SendInternal(packer.GetPackedData()); }
protected override void fixMessage(Packer packer, byte[] message) { int toSendAccNum = this.sendAccNum++; packer.Pack((byte)Protocol.Reliable); packer.Pack(toSendAccNum); packer.Pack(message); MessageResendTimer timer = new MessageResendTimer(); timer.accnumber = toSendAccNum; timer.message = packer.GetPackedData(); timer.stopWatch.Start(); connection.reliableTimer.addResender(timer); }
private byte[] buildOrderedMessages(UnPacker unPacker) { List<int> keysToRemove = new List<int>(); Packer packer = new Packer(unPacker.remaining()); packer.Pack(unPacker.UnpackByteArray(unPacker.remaining())); foreach (var item in this.outOfOrderMessages.Keys) { if (this.lastOrderedMessage + 1 == item) { keysToRemove.Add(item); this.lastOrderedMessage++; packer.Pack(this.outOfOrderMessages[item]); } else { break; } } keysToRemove.ForEach((x) => this.outOfOrderMessages.Remove(x)); return packer.GetPackedData(); }
protected override void fixMessage(Packer packer, byte[] message) { packer.Pack((byte)Protocol.Ordered); packer.Pack(sendReciveSequenceNumber++); packer.Pack(message); }
private UdpClient SendConnectionAck(IPEndPoint endpoint) { UdpClient client = new UdpClient(new IPEndPoint(IPAddress.Any, 0)); client.Connect(endpoint); Packer packer = new Packer(4); packer.Pack(((IPEndPoint)client.Client.LocalEndPoint).Port); client.Send(packer.GetPackedData(), 4); return client; }