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
375 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
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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
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…

839 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