ali_kerem has asked for the wisdom of the Perl Monks concerning the following question:
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Sockets! Controlling Receiver part
by flexvault (Monsignor) on Jun 23, 2013 at 16:08 UTC | |
by ali_kerem (Acolyte) on Jun 24, 2013 at 05:20 UTC | |
|
Re: Sockets! Controlling Receiver part
by flexvault (Monsignor) on Jun 25, 2013 at 09:36 UTC | |
by ali_kerem (Acolyte) on Jun 27, 2013 at 11:34 UTC |