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

Support Framing #1

Open
gajanak opened this issue Sep 28, 2024 · 1 comment
Open

Support Framing #1

gajanak opened this issue Sep 28, 2024 · 1 comment

Comments

@gajanak
Copy link

gajanak commented Sep 28, 2024

Hello,

i found your tutorial, and only want you give some hints for your future tcp experience.

On reading data from a tcp socket - you should never expect to read one message.
It can always happen that you read only a part of it, or multiple...
This happens in real world scenarios were TCP split the data on the lower layer.

Perhaps you should define a Start or Stop Char.
Some Protocols like SMTP use \r\n. As End of Message Marker
Other Use binary chars like 0x01,0x02 - with quoting this in the Message.
( Sample is BER which use additional Tag identifier https://www.oss.com/asn1/resources/asn1-made-simple/asn1-quick-reference/basic-encoding-rules.html)

This "Framing" comes from Serial-Line Communication. On TCP you can expect that never any data gets lost. So you can make it simple.

On read you can read until such a char ... handle this in your routing.
And then handle the data following the End Marker -
or wait for more data.

Another way is some kind of LV-Encoding (Length,Value). Here you send the length of the frame as first data.
So Client read exactly this number of bytes, and then expect a length again.

This is only minimal examples , to show the concepts... ;)

Good Luck and I wish you much fun with creating new protocols. ;)

@ACR1209
Copy link
Owner

ACR1209 commented Sep 28, 2024

Hello!

Thanks for the feedback, really cool. Yeah, this was more of a quick hacky way of doing a protocol because it was made for a college class more than anything haha.

Appreciate the input, I thank you for taking the time to explain this to me and might try to implement this into the project someday :)

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

No branches or pull requests

2 participants