Hello All,

I have a question about socket programming which is about controlling the data through Socket->Recv.

I have a script that sends and receives commands to system RCV from system SND according a protocol which uses hexadecimal codes. I send a command to RCV and according to its meaning it does its job and reply to SND with one or more commands, then it continues until SND sends deactivate command. Each message has a head and tail obviously. So when I receive a message I convert into hex to understand it, like;

... my $Sock= new IO::Socket::INET ( PeerAddr => $Dest # Open connection to destination ,PeerPort => $Port # Open connection through port ,Proto => 'tcp' # Open connection as TCP #,Blocking => 0 # Connection will be blocking m +ode or not. 0 is non-blocking ) or die "Could not open socket :$!"; ... $Sock->recv($DataToRecv,4096); ;; # Convert into hex string my $responseMSG = unpack 'H*', $DataToRecv; ...

The problem is, sometimes SND sends a long command and RCV replies many long commands and it doesnt fit in my defined length. So lets say it gets 10 messages with head and tail but it loses 11th tail and the next time it receives a message which continues 11th message, meaning no head but body and tail...

When I increase data length, its not 11th message but 21th message this time. So there is no limitations, sometimes I see three messages without proper head.

So due to this problem I want to control receiver part with head and tail packets, but I don't know how. Because I convert it to meaningful hex part after I receive it, not while receiving it...

Pleease guide me or at least a hint, thanks.


In reply to Sockets! Controlling Receiver part by ali_kerem

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.