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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
remove duplicates from the csv file 13 108
Removing file extension within a file. 4 92
Port 80 requests 16 95
Get a Perl script to return content from a module 7 80
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…
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…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

776 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