Solved

How do I write to and read from a socket using a perl client in an object oriented way?

Posted on 2011-03-11
3
376 Views
Last Modified: 2012-05-11

 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
0
Comment
Question by:CarlCP
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 31

Accepted Solution

by:
farzanj earned 500 total points
ID: 35108236
0
 
LVL 9

Expert Comment

by:Suhas .
ID: 37319323
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question