Object Oriented Perl interface to read from and write to a socket
- by user654967
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