server/client pair using a udp socket

Posted on 2005-04-07
Last Modified: 2012-05-05
the server should receive 1 and only 1 client and print "." to the shell once a second.  the socket should listen on port 9999, close the connection, remove the socket, and exit on the TERM sig.

I have included some code as follows:
use Socket;
my $sin = sockaddr_un(9999,INADDR_ANY);
bind (SERVER,$sin) || die $!;
this is where I am getting confused because I've read something similar to this
use IO::Socket;

$socket= IO::Socket::INET->new(PeerAddr =>$remote_host,
                                                 PeerPort  =>9999,
                                                 Proto       =>"udp",
                                                 Type       =>SOCK_DGRAM)  || die "Couldn't connect to $remote_host:$remote_port : $@\n";

Question by:targetddc
    LVL 84

    Accepted Solution

    #!/usr/bin/perl -w

    my $remote_host="";
    my $remote_port=9999;
    use strict;
    use warnings;
    use Socket;
    socket(SOCKET, PF_INET, SOCK_DGRAM, getprotobyname('udp'))   || die "socket: $!";
    bind(SOCKET, sockaddr_in($remote_port, inet_aton($remote_host))) || die "bind: $!";
    if( fork() == 0 ){


      while( 1 ){
        print STDERR $! unless send(SOCKET,".",0,sockaddr_in($remote_port, inet_aton($remote_host)));
        sleep 1;
      sub cleanup{
        close SOCKET;
    print $_||$! while recv(SOCKET,$_,1,0);


    Author Comment

    good show.  Curious as to if this can be written using a server/client pair?  Perhaps I'm stating the question wrong.  Is there a way to write a server program and a client program?
    Thanks for your input!!!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
    Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now