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

Hi, I'm trying to make a little 'status' grabber for a counter strike server. What i need to do is connect to port 27015 using UDP, and then send a command to the server (˙˙˙˙details\x00/˙˙˙˙players\x00/˙˙˙˙rules\x00). Then i want to listen for a reply. However, Ive used INET sockets, but i can't get a reply- it seems it's only one way. Any ideas?

Replies are listed 'Best First'.
Re: UDP Sockets
by Zaxo (Archbishop) on Jun 19, 2005 at 22:41 UTC

    By your code, you never asked the socket what the reply was. Call recv, or with IO::Socket, defined $sock->recv(my $rmsg, $len, $flags) or die $!; See perlipc.

    After Compline,
    Zaxo

      A quick search using google revealed this link with a short tutorial on socket programming with UDP.

      UDP is a packet-oriented protocol, so you have to send whole packets and receive whole packets. You can't try reading a UDP socket line by line like you may do with TCP.

      Tried that, but nothing was returned :-(. Maybe my counter strike server isn't sending back any information. Perhaps i've got the wrong command to send it :-S.
Re: UDP Sockets
by davidrw (Prior) on Jun 19, 2005 at 19:45 UTC
    Can you post code? I've haven't used it personally, but perhaps Net::UDP will help? Which INET modules are you currently using? Also, what about the obvious question of the port being open and not blocked by firewalls, the server actually be on/working, etc?
      I've got this far:
      #!/usr/bin/perl use IO::Socket; $sock = IO::Socket::INET->new(PeerAddr => '66.199.241.106', PeerPort => '27015', Proto => 'udp'); $msg="˙˙˙˙details\x00/˙˙˙˙players\x00/˙˙˙˙rules\x00"; $sock->send($msg) or print $!;
      But, then, how do I get the response? Firewalls are all off- I've found some PHP code that does the same sort of thing and it works.
Re: UDP Sockets
by Akhasha (Scribe) on Jun 21, 2005 at 04:44 UTC
    <voice type="radio">Counter Terrorists Win!</voice>