chrism01 has asked for the wisdom of the Perl Monks concerning the following question:

I'm trying to write a program that sends udp pkts repeatedly to another system (Radius / radiator) that communicates via udp.
Here's my socket creation
$send_socket = IO::Socket::INET->new(PeerAddr => $server, PeerPort => $port, Proto => "udp", Type => SOCK_DGRAM ) or $socket_errmsg = "Couldn't create socket to $server port $port: + $@\n";
and pack the dest address
$addr = Socket::inet_aton($server_fqdn); $packed_addr = Socket::sockaddr_in($acct_port, $addr);

create/assemble a radius style pkt (rp), then the call is
$result = $rp->sendTo( $socket, $packed_addr );
which calls the Radius sub which does:
sub sendTo { my ($self, $socket, $paddr, $p) = @_; $self->{SendTo} = $paddr; if (!send($socket, $self->{Packet}, 0, $self->{SendTo}) && $! =~ /^Connection refused/ ) { &main::log($main::LOG_ERROR, "sendTo: send failed: $!", $p); return; } return 1; }

(You can assume all the vars are declared, initialized correctly etc.)
I always get the error: Socket is already connected, even on the 1st send. However, if I hack the radiator sub send call to
if (!send($socket, $self->{Packet}, 0)
it works perfectly. I really don't want to do this, but I don't understand why the std ver doesn't work.

Replies are listed 'Best First'.
Re: UDP Send Socket: Socket is already connected (don't connect)
by tye (Sage) on Dec 15, 2004 at 23:58 UTC

    Then leave off PeerAddress and PeerPort on the c'tor.

    - tye        

      Thx a lot, :-) ...
      I had a nasty feeling it was simple, but I thought you had to tell it where to connect to....
      Cheers
      Chris
      PS Consider me suitably embarrassed...