public void SendSegments(PacketOut Out) { long PSize = Out.Length - Out.OpcodeLen - PacketOut.SizeLen; // Size = Size-len-opcode byte[] Packet = new byte[PSize]; Out.Position = Out.OpcodeLen + PacketOut.SizeLen; //Out.Read(Packet, 0, (int)(PSize)); List <byte> Header = new List <byte>(5); int itemcount = 1; while (PSize > 0x7f) { Header.Add((byte)((byte)(PSize) | 0x80)); PSize >>= 7; itemcount++; if (itemcount >= Header.Capacity + 10) { Header.Capacity += 10; } } Header.Add((byte)(PSize)); Header.Add((byte)(Out.Opcode)); Log.Tcp("Header", Header.ToArray(), 0, Header.Count); SendTCP(Header.ToArray()); // ugly needs to fix byte[] buffer; long bytesleft = PSize; int start = 0; while (PSize > 1460) { if (bytesleft < 1460) { break; } buffer = new byte[(start + 1460) - start]; Out.Read(buffer, start, (start + 1460)); SendTCP(buffer); start += 1461; bytesleft -= 1461; } if (bytesleft > 0) { buffer = new byte[(start + bytesleft) - start]; Out.Read(buffer, start, (int)(start + bytesleft)); SendTCP(buffer); } }
public void SendTCPCuted(PacketOut Out) { long PSize = Out.Length - Out.OpcodeLen - PacketOut.SizeLen; // Size = Size-len-opcode byte[] Packet = new byte[PSize]; Out.Position = Out.OpcodeLen + PacketOut.SizeLen; Out.Read(Packet, 0, (int)(PSize)); List <byte> Header = new List <byte>(5); int itemcount = 1; while (PSize > 0x7f) { Header.Add((byte)((byte)(PSize) | 0x80)); PSize >>= 7; itemcount++; if (itemcount >= Header.Capacity + 10) { Header.Capacity += 10; } } Header.Add((byte)(PSize)); Header.Add((byte)(Out.Opcode)); socket.Send(Header.ToArray()); socket.Send(Packet); Out.Dispose(); }
public void SendTCPCuted(PacketOut outPacket) { long pSize = outPacket.Length - outPacket.OpcodeLen - PacketOut.SizeLen; // Size = Size-len-opcode byte[] packet = new byte[pSize]; outPacket.Position = outPacket.OpcodeLen + PacketOut.SizeLen; outPacket.Read(packet, 0, (int)(pSize)); List <byte> header = new List <byte>(5); int itemcount = 1; while (pSize > 0x7f) { header.Add((byte)((byte)(pSize) | 0x80)); pSize >>= 7; itemcount++; if (itemcount >= header.Capacity + 10) { header.Capacity += 10; } } header.Add((byte)(pSize)); header.Add((byte)(outPacket.Opcode)); Log.Tcp("Header", header.ToArray(), 0, header.Count); Log.Tcp("Packet", packet, 0, packet.Length); //Log.Dump("Header", header.ToArray(), 0, header.Count); //Log.Dump("Packet", packet, 0, packet.Length); SendTCP(header.ToArray()); SendTCP(packet); outPacket.Dispose(); }