in reply to What is the difference between udp client and server?

With UDP sockets, the server receves packets, and the client sends them

If you can get hold of a copy, then you should take a look at the examples in Perl Cookbook (O'Reilly). Otherwise, take a look at IO::Socket::INET in CPAN.

Here is a quick example:

Client:

my $sendSock = IO::Socket::INET->new( 'Proto' => 'udp', 'PeerPort' => $udp_port, 'PeerAddr' => $hostname, ) or die("Error creating socket $!"); $sendSock->send($data) or die("Socket send error $!");

Server:

my $listenSock = IO::Socket::INET->new('LocalPort'=>$udp_port, 'Proto' +=>'udp'); my $readBuff; $listenSock->recv( $readBuff, $MAX_BYTES );

Note that the server above will block until some data is received.

Replies are listed 'Best First'.
Re^2: What is the difference between udp client and server?
by ikegami (Patriarch) on Nov 10, 2010 at 16:31 UTC

    With UDP sockets, the server receves packets, and the client sends them

    ow! That's not true. For starters, UDP doesn't know anything of client and server. sundialsvc4 has a great answer you should read.

    Both the server and the client can both send and receive. Both the client and server almost always both send and receive. (Conversations are generally variations of the following: The client sends a request, the server receives a request, the server sends a response, the client receives a response.)