Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

UDP Server

by maxy (Novice)
on Dec 01, 2008 at 23:20 UTC ( [id://727253]=perlquestion: print w/replies, xml ) Need Help??

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

Hi Everyone! I want to create a udp server, which listens for clients, and then reply to them, i have written a sub function for it, but it doesn't listen, and exits with a warning like this:Can't call method "recv" on an undefined value at .. line 114 the sub function is like this:
sub listen{ use IO::Socket; my $port1 = @_; $proto = 'udp'; $socket1 = new IO::Socket::INET (LocalPort => $port1,Proto=> $proto)or + die "Cannot Listen On The Socket $@"; print " Waiting for connection\n"; my $MAX_TO_READ = 512; my $datagram; while (1){ $server->recv($datagram,$MAX_TO_READ); if($datagram ne '') { print "\nReceived message '", $datagram,"'\n"; } # If client message is empty exit else { print "Cilent has exited!"; exit 1; } return $server; } }
and i am calling it like this: &rdt_listen($ARGV[1]) thanx in advance

Replies are listed 'Best First'.
Re: UDP Server
by Your Mother (Archbishop) on Dec 01, 2008 at 23:26 UTC

    The error message is pretty self-explanatory. $server is undefined so you can't call ->recv on it. Nowhere in your sample is $server declared or created. Take a look at $socket1. :)

    You are using strict and warnings, right? These kinds of developer errors aren't impossible with them on but they are a lot easier to avoid.

      how stupid of me,thanx, i m in hurry so i didn't c it,

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://727253]
Approved by ww
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2024-04-24 02:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found