Skip to content

A default behaviour for splitting a message into multiple packets? #175

Open

Description

@Artromskiy

I tried sending about 4 KB of data in a single message, and it never got through. The problem is the size; small messages are guaranteed to get through. I'd like to see some kind of build-in mechanism for splitting and sending messages in multiple batches without adding that functionality on top.

Activity

  1. Artromskiy commented on Oct 7, 2025

    @Artromskiy
    Author

    Right now I'm just reinventing the wheel

           private List<Message> GetSplitted<T>(ReadOnlySpan<byte> written, List<Message> messages)
                where T : ICommandData
            {
                // write true if splitted
                // write true if last split index
                // write split index // 2^16 max
                // write uid // 2^16 max
    
                int splitCount = written.Length / SplitSize +
                    (written.Length % SplitSize == 0 ? 0 : 1);
                if (splitCount > ushort.MaxValue)
                    throw new NotSupportedException();
                var commandId = CommandIds.GetId<T>();
                ushort uid = _splitMessageId++;
                for (int i = 0; i < splitCount; i++)
                {
                    var splitMessage = Message.Create(MessageSendMode.Reliable, (ushort)commandId);
                    splitMessage.AddBool(true); // split
                    splitMessage.AddUShort(uid); // uid
                    splitMessage.AddUShort((ushort)i); // index
                    splitMessage.AddBool(i == splitCount - 1); // is last
    
                    var splitWrite = written[(i * SplitSize)..];
                    splitWrite = splitWrite[..Maths.Min(splitWrite.Length, SplitSize)];
                    WriteToMessage(splitWrite, splitMessage);
                    messages.Add(splitMessage);
                }
                return messages;
            }
  2. added
    Under ConsiderationIt remains unclear whether this feature is necessary or worth implementing—make your case!
    on Oct 23, 2025
  3. megalithos commented on Jan 28, 2026

    @megalithos
    Contributor

    Hi! I think a streaming feature would be a great addition to the library. For this kind of data, you really don't want to drop all packets on the wire at once; using congestion control is a much better approach.
    I’ve actually implemented a version of this in my fork (https://github.com/megalithos/Riptide) that handles streaming for things like 1MB files quite fast. It’s currently working well in production for me. The code could still be improved, but I’d be happy to send over a PR if you’re interested in using it as a starting point or an experimental preview.

  4. Lyraedan commented on Mar 27, 2026

    @Lyraedan

    I implemented Riptide into my ONI Together mod for my LAN implementation, my method was to basically limit the packet size to about 1000 bytes then taking a lil off for any additional overhead and then chunk the packets. Frequently ran into InsufficientCapacityException before doing this.

    So this would be a really cool feature to have natively

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Feature RequestNew feature or requestUnder ConsiderationIt remains unclear whether this feature is necessary or worth implementing—make your case!

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions