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
In reply to UDP Server
by maxy
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.