in reply to (tye)Re: IO:Socket::NET problem & Counter-Strike
in thread IO:Socket::NET problem & Counter-Strike

So If I understand you correctly....I should change the code from this....

while ($socket->recv(my $in, 1024) ) { my $sock = IO::Socket::INET->new( Proto => 'udp', PeerAddr =>'127.0.0.1:50000'); print $sock $in; }

To this....

my $sock = IO::Socket::INET->new( Proto => 'udp', LocalAddr =>'127.0.0.1:50000'); while ($socket->recv(my $in, 1024) ) { print $sock $in; }

But do I need to specify the PeerAddr as well in the new statement? Also it would appear it won't reuse the socket, after one iteration, it says cannot write to socket.

I admit I am not too smart and I looked at the Module docs, but the examples there don't specify a Peer and Local in the same command, am I able to?

Thanks again Tye, I appreciate you taking the time to help me!

-Myron DaChump

Replies are listed 'Best First'.
(tye)Re2: IO:Socket::NET problem & Counter-Strike
by tye (Sage) on Mar 31, 2001 at 10:03 UTC

    Well, I don't see how it could write to the socket the first time since you don't give a destination address/port. Also, I strongly discourage specifying a local IP address and I don't recommend specifying a local port number. Certainly if you specify a local port number then you should be checking whether the new() fails!

            - tye (but my friends call me "Tye")
      Okay, then I am confused. I am not so sharp, so give me a leg up here. Would you mind actually composing an example socket for me?

      You are of course right about the NEW statment, moving the creation to outside of the loop does run, but when I start the other script to listen on port 50000 it says that the socket is already in use. I am lost boss.

      -Myron DaChump

        Hm, it looks like you somehow change "Peer" to "Local" when you moved those lines. Change "Local" back to "Peer" and try again.

        Update: Note the >>>Tagged<<< parts:

        while ($socket->recv(my $in, 1024) ) { my $sock = IO::Socket::INET->new( Proto => 'udp', >>>Peer<<<Addr =>'127.0.0.1:50000'); print $sock $in; }
        To this....
        my $sock = IO::Socket::INET->new( Proto => 'udp', >>>Local<<<Addr =>'127.0.0.1:50000'); while ($socket->recv(my $in, 1024) ) { print $sock $in; }
        so the code should look like this:
        my $sock = IO::Socket::INET->new( Proto => 'udp', PeerAddr =>'127.0.0.1:50000'); while ($socket->recv(my $in, 1024) ) { print $sock $in; }

                - tye (but my friends call me "Tye")