Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

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 = ""; $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

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

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

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

    How do I use this? | Other CB clients
    Other Users?
    Others drinking their drinks and smoking their pipes about the Monastery: (5)
    As of 2021-04-22 23:09 GMT
    Find Nodes?
      Voting Booth?

      No recent polls found