Hi,
Haven't actually worked with UDP - I had enough trouble printing what was
sent to a TCP connection. Based on what I had to do for that exercise I
suggest trying the following. '$len' is a number >= the length of the
message received (in bytes) and $flags='' (2 single quotes, ie void)

$remote = IO::Socket::INET->new(
Proto     => "udp",
        Type      => SOCK_DGRAM,
        LocalAddr => "159.206.48.202:514") or die "cannot open syslog,
udp.$@\n$!\n";
while ( $client = $remote->accept()) {
# $client is the new connection

$client->recv($data_read,$len, $flags)
    or die "Can't recv: $@\n$!\n";
print "Received:$data_read";

It's a good idea to include '$!' in your 'die' statements, and '$@' as well,
where sockets are concerned. ( In fact, '$!' may not be all that useful for
sockets, but I include it anyway.)
If that doesn't work, here is the opening section of my TCP script. It may
(or may not) hold the key to the problem.
$server_port =514 # in your case

$remote = IO::Socket::INET->new(LocalPort => $server_port,
                                Type      => SOCK_STREAM,
                                Reuse     => 1,
                                Listen    => 10 )   # or SOMAXCONN
    or die "Couldn't be a tcp server on port $server_port : $@\n$!\n";

HTH

Cheers,
Rob
Visit our website at http://www.kalinabears.com.au
----- Original Message -----
From: Basil A. Daoust <[EMAIL PROTECTED]>
To: perl <[EMAIL PROTECTED]>
Sent: Tuesday, February 20, 2001 8:03 AM
Subject: still stuck trying to listen to port.


> I'm trying to listen to port 514 using UDP.
> I've read the perllibc man page shipped with Active Perl and the
> Perl book.  But most examples are around TCP.  I've got the code
> to the point it will run.  It just doesn't check any traffic to the
> screen.
>
> Here are two examples of my many many attempts:
> #!/usr/bin/perl -w
> use IO::Socket;
>
> $remote = IO::Socket::INET->new(
> Proto     => "udp",
>         Type      => SOCK_DGRAM,
>         LocalAddr => "159.206.48.202:514") or die "cannot open syslog,
> udp.\n";
>
> print "Started listening\n";
> while ( <$remote> ) { print };
> print "ended\n";
>
>
> here is attempt #2:
> #!/usr/bin/perl -w
> use strict;
> require 5.002;
> use Socket;
> use Sys::Hostname;
>
> print "Start\n";
> my ( $a,
>      $iaddr,
>      $paddr,
>      $port,
>      $proto );
>
> $iaddr = gethostbyname(hostname());
> print "iaddr is $iaddr.\n";
> print inet_ntoa($iaddr),"\n";
> $proto = getprotobyname('udp');
> print "proto is $proto.\n";
> $port  = getservbyname('syslog','udp');
> print "port is $port.\n";
> $paddr = sockaddr_in($port,$iaddr);
> print "paddr is $paddr.\n";
>
> $a=socket(SOCKET, PF_INET, SOCK_DGRAM, $proto) or die "Socket: $!";
> print "Socket connect returned $a.\n";
> #$a=bind(SOCKET,$paddr) or die "bind failed\n";
> #print "bind returned $a.\n";
> $a=connect(SOCKET,$paddr) or die "Connect failed\n";
> print "connect returned $a.\n";
> while ( <SOCKET> ) { print; }
> _______________________________________________
> Perl-Win32-Users mailing list
> [EMAIL PROTECTED]
> http://listserv.ActiveState.com/mailman/listinfo/perl-win32-users

_______________________________________________
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/perl-win32-users

Reply via email to