CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Messages Not Going Out on UDP with Script Run by xinetd

 



TangoOversway
New User

Feb 23, 2011, 9:36 PM

Post #1 of 2 (734 views)
Messages Not Going Out on UDP with Script Run by xinetd Can't Post

I've done this with a Java/Perl combo and not using xinetd and just having my Perl server using a socket and acting like a daemon, but I need to change it for a number of reasons.

I have a system that will be plugged into different LANs and when it's plugged in, I need to be able to find it from other computers (all will be running Linux), so I'm using two Perl scripts. One (the client) sends out a broadcast message, essentially saying, "Where is my_lost_system?" and the system I'm looking for (the server, running xinetd) receives that and answers back.

I have xinetd set up to run my test program on port 7071 using UDP. Here is the config in /etc/xinetd.d:

Code
# default: on 
# description: System locater
service syslocate
{
port = 7071
socket_type = dgram
protocol = udp
# socket_type = stream
# protocol = tcp
wait = no
user = nobody
group = nobody
server = /thresh/global/test/t-sys
log_on_success += USERID
log_on_failure += USERID
disable = no
}


When I had this set to use TCP, I could telnet in and I saw that the server was responding to the telnet client messages and sending those responses back over the LAN.

But then I changed it to UDP. I ran the program on the other computer and, using Wireshark, I've verified the client sends the messages to this server and they show up in the server log file. But the server does not send any messages back to the client. I've verified with Wireshark that nothing is sent out by the server on UDP. (Unlike with TCP, when it did send the data out.)

Any idea what I'm doing wrong or what I have to change from TCP to UDP with this kind of setup?

Also, totally as an aside, but a "while we're on it," in the subroutine at the end, I had to have 'system("/bin/echo");' as a line terminator or messages would not be sent back under TCP. I tried using both /r and /n at the end of the line, and they did not work. Is there a character I need to send at the end of a message to the other system so I don't have to use echo?

Thank you for any help on this!

Here is my code:

Code
#!/usr/bin/perl 
#System Location Service
#Testing...

use IO::Socket;

use MyPerl::Time; #My own module to easily format the time/date

use strict;

our ($in, $cmd, $host, $call, $reply, $log, $addy, $sender);

$call = "Seeking my system";
$reply = "This is my system";
$log = "/thresh/global/test/syslocate.log";

open LOG, ">>$log";
$addy = $ENV{REMOTE_HOST};
#Get our host name to help ID us
open (STREAM, "</etc/hostname");
$host = <STREAM>;
close STREAM;
$host =~ s/\n//g;
print LOG humantime()."\tStarting program on host: $host, received message from $addy\n";
$call = "$call $host";
$reply = "$reply $host";

while (1) {
$in = <STDIN>;
$in =~ s/\n$//;
if ($in =~ /$call/i) {
output($reply);
} elsif ($in =~ /^q/) {
last;
} else {
output("Received: $in");
}
}
print LOG humantime()."\tExiting program\n";
close LOG;
exit();

sub output {
foreach (@_) {
print "$_";
print LOG humantime()."\t$ENV{REMOTE_HOST}\t$_\n";
system("/bin/echo ");
}
return;
}



TangoOversway
New User

Feb 24, 2011, 9:31 AM

Post #2 of 2 (726 views)
Re: [TangoOversway] Messages Not Going Out on UDP with Script Run by xinetd [In reply to] Can't Post

I just spent time talking with someone locally who knows this stuff pretty well. It turns out this isn't possible.

UDP is monodirectional, so the programs in C that solved this did it by opening a new socket.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives