I don't have an answer to the main part of your question, as I haven't used UDP, but I have an answer for something fundamental that might be missed.

You don't need to fork or thread to use TCP efficiently. It is sometimes a good way to do it, but here is an example of another way. If you like it, read the manual pages for the packages useed. Notice in particular IO::Select.

use IO::Socket; use IO::Select; use Tie::RefHash; #there are also lots of slower ways to keep track of + the connections ;) use POSIX; #for usefull constants my %connections; my $port = 5000; tie %connections, qw( Tie::RefHash ); # so we can use refs as hash key +s my $server = IO::Socket::INET->new( Listen => SOMAXCONN, LocalPort => $port, Reuse => 1, Proto => 'tcp', ) or die "can't open connection: $!"; $server->blocking( 0 ); my $select = IO::Select->new( $server ); while('eternity'){ foreach my $connection ( $select->can_read(60) ) { if ( $connection == $server ) { # new connection waiting my $client = $connection->accept; $client->blocking( 0 ); $select->add( $client ); $connections{$client} = time; # I like to know how long a user + has been connected, you could also set this to anything; we're just +using the key for fast lookup. } elsif ( exists $connections{$connection} ) { # user sending us data my $length = $connection->sysread(my $data,POSIX::BUFSIZ); if (defined $length && length $data) { print "got '$data' from ",$connection->peerhost,':',$conne +ction->peerport,"\n"; } else { # No data, probably EOF or an error, so close $select->remove( $connection ); delete $connections{$connection}; } } }

--
Snazzy tagline here

In reply to Re: Developing an UDP chat server/client by Aighearach
in thread Developing an UDP chat server/client by Mandor

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.