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


Hi Monks

I have created a UDP socket by using the following code
use IO::Socket::INET; $MySocket=new IO::Socket::INET->new( LocalAddr=>Local_IP, LocalPort=>Local_Port +, PeerPort=>Peer_Port, Proto=>'UDP', PeerAddr=>Peer_IP, ); $MySocket or die "no socket :$!";

Is there any way (or any value ) to be assigned in the PeerAddr and Peerport, so that this socket will recv the data from any Peer IP and Peer Port?

Plz suggest me.

Regd's
Sanjay
  • Comment on How to create a socket so that it can receive the data from any peer IP and port?
  • Download Code

Replies are listed 'Best First'.
Re: How to create a socket so that it can receive the data from any peer IP and port?
by ikegami (Patriarch) on Dec 29, 2008 at 09:02 UTC
    Get rid of PeerPort and PeerAddr. And LocalAddr for that matter. And you have "new" there twice?!
    use IO::Socket::INET; my $sock = IO::Socket::INET->new( Proto => 'UDP', LocalPort => $port, ) or die("Can't create socket: $!\n");

      Hi

      Thanks a lot for your reply. Now it is working fine.

      Regd's
      Sanjay
Re: How to create a socket so that it can receive the data from any peer IP and port?
by Anonymous Monk on Dec 29, 2008 at 08:49 UTC
Re: How to create a socket so that it can receive the data from any peer IP and port?
by talexb (Chancellor) on Dec 29, 2008 at 08:57 UTC

    The short answer is no. The long answer is, sure you can connect to any IP on any port -- how many trillions of connections do you want to make?

    Perhaps you can explain what your goal is.

    Alex / talexb / Toronto

    "Groklaw is the open-source mentality applied to legal research" ~ Linus Torvalds

      He's using UDP which doesn't have the concept of a connection. And like a TCP socket can receive connections from any source on the network, UDP sockets can receive datagrams from any source on the network.