Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handle TCP fragmentation #2

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

SkeLLLa
Copy link

@SkeLLLa SkeLLLa commented Mar 24, 2017

This PR for handling TCP packet fragmentation. It defines simple protocol with header and data.
Format:

const HEADER_START = '\u0001';
const DATA_START = '\u0002';
const DATA_END = '\u0003';
const PACKET_END = '\u0004';
const HEADER_DELIMITER = '/';

Message:
<HEADER_START>
<id><HEADER_DELIMITER><method><HEADER_DELIMITER><data length><HEADER_DELIMITER><format><HEADER_DELIMITER><error>
<DATA_START>
<data_bytes>
<DATA_END>
<PACKET_END>

This protocol is needed to handle situations when TCP protocol divide long message into smaller parts to fit MTU.

@SomeoneWeird as for current version of tcp-transport, the new one covers 100% functionality + fragmentation handling. But if it's necessary we can modify protocol to handle true binary data (now it can handle only binary data that doesn't contain any protocol characters). If binary transport is needed, then protocol should be slightly different - with fixed-length header places for metadata. This will lead to maximum data size limit (because we'll have limited number of bytes for data length in header).

PS: Do not rush to merge this PR. Depending on decision on previous question the code could be simplified a bit or rewritten.

@SomeoneWeird
Copy link
Member

I'd rather not invent our own protocol. Can we use msgpack or something?

@SkeLLLa
Copy link
Author

SkeLLLa commented Apr 7, 2017

@SomeoneWeird msgpack doesn't handle tcp fragmentation. It just like JSON, but smaller. You still should separate one packet from another and that's why it will also need some kind of packet separator (and this is also "own protocol"). But as msgpack transmitting buffers it will need fixed-length header that will store information about packet data size.

fix chunked decoder to handle TCP Nagle algorithm packet merging
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants