Hello flexvault,
Thank you for your time and effort reading and replying to my question/commends. You are absolutely right about it, as I said this is a brief idea that needs experimentation to become generic and more solid.
My assumption was build upon the user reads the length of the string (e.g. 40 characters) creates a string for transmission containing this number.
For example $msg = $length . " " . $txt;. So when the receiver will get the message he knows that he needs to subtract the $length from the length($msg); in order to get the pure message which would be something like 40 character + 3 (length description with the space) = 43 characters. So if the user skips the first 3 characters of the message and reads the rest 40 can know that he got the whole message. Even in case the message was segmented.
Well this is only a brief idea that I was planning to implement.
Sample of code of my idea by using substr including the output:
#!/usr/bin/perl use strict; use warnings; my $msg = "This is just a sample of message."; my $length = length($msg); my $number = length($length); print "\$number: ".$number."\n"; my $transmit = $length . " " . $msg; print "\$transmit: ".$transmit."\n"; my $receive = substr $transmit, 3; print "\$receive: ".$receive."\n"; __END__ $number: 2 $transmit: 33 This is just a sample of message. $receive: This is just a sample of message.
The solution as it is right now, can not be generic, because the receiver needs to know how many digits need to subtract from the $msg. In case that someone wants to make a generic solution, I would recommend the user to read the string and get the actual length before subtracting. As I said, it needs some small experimentation to become generic and more solid solution, but I think it is possible as an idea to be implemented.
Again thank you for your time and effort reading and replying to my query.
In reply to Re^4: how to control segmented messages in TCP chat client
by thanos1983
in thread how to control segmented messages in TCP chat client
by thanos1983
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |