Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Based on the sample provided in this page, I have written a server handler and a client - the purpose is which is that when the client opens a socket connection on a specific port and sends data, the server receives it, parses it and logs it in a log file. The inetd and the services files have been configured and I know that it is done correctly because when my server program has compilation errors, the corresponding error message is displayed on the console where I run my client program. But when all the errors have been fixed, the job that the server program is supposed to be doing is not getting done - log file is not getting updated and the response it spits out is not getting communicated to the client. Can someone please review the code and let me know what is it that I am doing wrong? Here are the codes I have for the server program and the client program:
The Server Program:
#!/usr/local/bin/perl5.00506 -Tw # add the -Tw for testing use strict; # use Time::Local; use CGI; use CGI::Carp qw(fatalsToBrowser); # use DB_File; # clean up path for security $ENV{PATH} = "/usr/local/bin"; $ENV{ENV} = ""; use Time::Local; my($day, $month, $year) = (localtime)[3,4,5]; my ($val, $send_ph_num, $mail, $var, $val_untaint, $tmp, $pin, $pagese +rvice, $backupmail); my %db; my (@output_msg_array, $msgto, $msg, $phonenumber, $sendphone, $sendba +ckup, $pager_email); my ($input_data); my $old_fh = select(STDOUT); $| = 1; select($old_fh); $input_data = <STDIN>; chomp $input_data; # remove the first character from the input string $input_data = substr($input_data, 2, (length($input_data)-1)); # Parse the input data my @values = split(' ',$input_data,5); my $cdsid = $values[0]; $msgto = $values[1]; $sendbackup = $values[2]; $msg = substr($values[4],1,(length($values[4])-1)); $phonenumber = ""; $sendphone = "N"; #print "Parsed Text\n"; #print "Parsed Text as Sender $cdsid To $msgto Message $msg\n"; open (LOGFILE, ">> log/batch_call.log"); printf LOGFILE ("%04d-%02d-%02d -- %s, %s, %s\n", $year+1900, $month+1 +, $day, $cdsid, $msgto, $msg); close(LOGFILE); print "Logged message successfully\n"; exit;
The Client program:
#!/usr/local/bin/perl/perl -w use IO::Socket; my ($remote_host, $remote_port, $socket, $answer); $remote_host = "x.y.com"; $remote_port = "5060"; print "Connecting to remote host....\n"; $socket = IO::Socket::INET->new(PeerAddr => $remote_host, PeerPort => $remote_po +rt, Proto => "tcp", Type => SOCK_STREAM) or die "Couldn't connect to $remote_host at $remote_po +rt: $@\n"; $socket->autoflush(1); print $socket "\x01jchakrab jchakrab N N Testing Text Pager thru Socke +t...\x10"; $answer = <$socket>; print ("$answer\n"); close($socket); exit;

In reply to Re: A Simple Socket Server Using 'inetd' by Anonymous Monk
in thread A Simple Socket Server Using 'inetd' by samizdat

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (1)
As of 2021-10-25 00:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My first memorable Perl project was:







    Results (89 votes). Check out past polls.

    Notices?