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