Object Oriented Perl interface to read from and write to a socket

Posted by user654967 on Stack Overflow See other posts from Stack Overflow or by user654967
Published on 2011-03-11T08:06:59Z Indexed on 2011/03/11 8:10 UTC
Read the original article Hit count: 269

Filed under:
|
|

I need a perl client-server implementation as a wrapper for a server in C#. A perl script passes the server address and port number and an input string to a module, this module has to create the socket and send the input string to the server. The data sent has to follow ISO-8859-1 encoding. On receiving the information, the client has to first receive 3 byte, then the next 8 bytes, this has the length of the data that has to be received next.. so based on the length the client has to read the next data.

each of the data that is read has to be stored in a variable and sent another module for further processing.

Currently this is what my perl client looks like..which I'm sure isn't right..could someone tell me how to do this..and set me on the right direction..

sub WriteInfo {

my ($addr, $port, $Input) = @_;

$socket = IO::Socket::INET->new(
    Proto    => "tcp",
    PeerAddr => $addr,
    PeerPort => $port,
);
unless ($socket) { die "cannot connect to remote" }


while (1) {

    $socket->send($Input);

}

}

sub ReadData {

while (1) 
{
my $ExecutionResult = $socket->recv( $recv_data, 3);
my $DataLength =  $socket->recv( $recv_data, 8);
$DataLength =~ s/^0+// ;
my $decval = hex($DataLength);
my $Data = $socket->recv( $recv_data, $decval);
return($Data);

}

thanks a lot..

Archer

© Stack Overflow or respective owner

Related posts about perl

Related posts about sockets