Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: A Simple Socket Server Using 'inetd'

by Anonymous Monk
on Aug 05, 2008 at 20:01 UTC ( [id://702469]=note: print w/replies, xml ) Need Help??


in reply to A Simple Socket Server Using 'inetd'

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;

Replies are listed 'Best First'.
Re^2: A Simple Socket Server Using 'inetd'
by samizdat (Vicar) on Aug 08, 2008 at 12:03 UTC
    Did you get my sample to execute successfully? I'd suspect that your inetd is not configured correctly.

    Don Wilde
    "There's more than one level to any answer."
      No, I did not execute the sample you have provided. There is no problem with the inetd config - because the server program is doing what it is supposed to do, but only thing is the client program not receiving the status back - looks like the socket is communicating only one way.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://702469]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2024-04-19 03:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found