Advertisement
saltycracker

udp_server.pl

Mar 30th, 2020
512
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 0.45 KB | None | 0 0
  1. #!/usr/bin/perl
  2.  
  3. use strict;
  4. use warnings;
  5. use autodie;
  6.  
  7. use IO::Socket::INET;
  8.  
  9. $| = 1;
  10.  
  11. my ($socket,$data);
  12.  
  13. $socket = new IO::Socket::INET (
  14.   LocalAddr => 'localhost',
  15.   LocalPort => 2323,
  16.   Proto => 'udp'
  17. );
  18.  
  19. my ($datagram,$flags);
  20.  
  21. while (1) {
  22.     $socket->recv($datagram, 42, $flags);
  23.     print "Received datagram from ", $socket->peerhost,", flags ", $flags || "none", ": $datagram\n";
  24. }
  25.  
  26. $socket->close();
  27.  
  28. exit(0);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement