public PutData ( byte data, int start, int length ) : void | ||
data | byte | |
start | int | |
length | int | |
Результат | void |
public void Send(byte[] data, int start, int length, SendOptions options) { //Prepare PacketProperty property = SendOptionsToProperty(options); int headerSize = NetPacket.GetHeaderSize(property); //Check fragmentation if (length + headerSize > _mtu) { //TODO: fix later if (options == SendOptions.Sequenced || options == SendOptions.Unreliable) { throw new Exception("Unreliable packet size > allowed (" + (_mtu - headerSize) + ")"); } int packetFullSize = _mtu - headerSize; int packetDataSize = packetFullSize - NetConstants.FragmentHeaderSize; int fullPacketsCount = length / packetDataSize; int lastPacketSize = length % packetDataSize; int totalPackets = fullPacketsCount + (lastPacketSize == 0 ? 0 : 1); for (int i = 0; i < fullPacketsCount; i++) { NetPacket p = GetPacketFromPool(property, packetFullSize); p.FragmentId = _fragmentId; p.FragmentPart = (uint)i; p.FragmentsTotal = (uint)totalPackets; p.IsFragmented = true; p.PutData(data, i * packetDataSize, packetDataSize); SendPacket(p); } if (lastPacketSize > 0) { NetPacket p = GetPacketFromPool(property, lastPacketSize + NetConstants.FragmentHeaderSize); p.FragmentId = _fragmentId; p.FragmentPart = (uint)fullPacketsCount; //last p.FragmentsTotal = (uint)totalPackets; p.IsFragmented = true; p.PutData(data, fullPacketsCount * packetDataSize, lastPacketSize); SendPacket(p); } _fragmentId++; return; } //Else just send NetPacket packet = GetPacketFromPool(property, length); packet.PutData(data, start, length); SendPacket(packet); }
/// <summary> /// Send message without connection /// </summary> /// <param name="message">Raw data</param> /// <param name="start">data start</param> /// <param name="length">data length</param> /// <param name="remoteEndPoint">Packet destination</param> /// <returns>Operation result</returns> public bool SendUnconnectedMessage(byte[] message, int start, int length, NetEndPoint remoteEndPoint) { if (!_running) { return(false); } NetPacket p = new NetPacket(); p.Init(PacketProperty.UnconnectedMessage, length); p.PutData(message, start, length); return(SendRaw(p.RawData, 0, p.RawData.Length, remoteEndPoint)); }
public void Send(byte[] data, int start, int length, SendOptions options) { //Prepare PacketProperty property = SendOptionsToProperty(options); int headerSize = NetPacket.GetHeaderSize(property); //Check fragmentation if (length + headerSize > _mtu) { if (options == SendOptions.Sequenced || options == SendOptions.Unreliable) { throw new Exception("Unreliable packet size > allowed (" + (_mtu - headerSize) + ")"); } int packetFullSize = _mtu - headerSize; int packetDataSize = packetFullSize - NetConstants.FragmentHeaderSize; int fullPacketsCount = length / packetDataSize; int lastPacketSize = length % packetDataSize; int totalPackets = fullPacketsCount + (lastPacketSize == 0 ? 0 : 1); DebugWrite("MTU: {0}, HDR: {1}, PFS: {2}, PDS: {3}, FPC: {4}, LPS: {5}, TP: {6}", _mtu, headerSize, packetFullSize, packetDataSize, fullPacketsCount, lastPacketSize, totalPackets); if (totalPackets > ushort.MaxValue) { throw new Exception("Too many fragments: " + totalPackets + " > " + ushort.MaxValue); } for (ushort i = 0; i < fullPacketsCount; i++) { NetPacket p = GetPacketFromPool(property, packetFullSize); p.FragmentId = _fragmentId; p.FragmentPart = i; p.FragmentsTotal = (ushort)totalPackets; p.IsFragmented = true; p.PutData(data, i * packetDataSize, packetDataSize); SendPacket(p); } if (lastPacketSize > 0) { NetPacket p = GetPacketFromPool(property, lastPacketSize + NetConstants.FragmentHeaderSize); p.FragmentId = _fragmentId; p.FragmentPart = (ushort)fullPacketsCount; //last p.FragmentsTotal = (ushort)totalPackets; p.IsFragmented = true; p.PutData(data, fullPacketsCount * packetDataSize, lastPacketSize); SendPacket(p); } _fragmentId++; return; } //Else just send NetPacket packet = GetPacketFromPool(property, length); packet.PutData(data, start, length); SendPacket(packet); }