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.

In reply to UDP Send Socket: Socket is already connected by chrism01

Title:
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, details, 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, summary, 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.