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
370 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
Comment Utility
0
 
LVL 9

Expert Comment

by:Suhas .
Comment Utility
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

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…
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now