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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Existing perl code to be changed for ftp to sftp handling 14 263
Perl for loop for 2000 ms 7 112
PERL - Find newest folder 12 194
Use Perl to Remove Large Quantity of Files Quickly 8 27
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…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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…

732 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