server/client pair using a unix socket

Posted on 2005-04-05
Last Modified: 2006-11-18
I need assistance with the following task and have included some code.  the server receives only 1 client a writes a "." once a second to the socket for the client to read.  The server should then close the connection, remove the socket and exit when given the TERM signal.

#!/usr/bin/perl -w
use Socket;
$socket_name = sockaddr_un("/tmp/mysock");
unlink "/tmp/mysock";
bind (SERVER, sockaddr_un("/tmp/mysock"))
or die "Can't create server: $!";

unlink "/tmp/mysock";
connect (CLIENT, sockaddr_un("/tmp/mysock"))
or die "Can't connect to /tmp/mysock: $!";
Question by:targetddc
    1 Comment
    LVL 84

    Accepted Solution

    #!/usr/bin/perl -w
    use strict;
    use Socket;

    socket(SERVER, PF_UNIX, SOCK_STREAM, 0) || die "socket: $!";
    unlink "/tmp/mysock";
    bind (SERVER, sockaddr_un("/tmp/mysock"))
        or die "Can't create server: $!";

    listen(SERVER,SOMAXCONN) || die "listen: $!";


        while( 1 ){  print CLIENT "."; sleep 1; }

    sub cleanup{
        close CLIENT;
        close SERVER;
        unlink "/tmp/mysock";

    #!/usr/bin/perl -w
    use Socket;
    socket(SOCK, PF_UNIX, SOCK_STREAM, 0) || die "socket: $!";
    connect (SOCK, sockaddr_un("/tmp/mysock"))
        or die "Can't connect to /tmp/mysock: $!";
    while( <SOCK> ){
        print "$_\n";

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Suggested Solutions

    Title # Comments Views Activity
    perl script help 12 99
    Strange perl issue 6 116
    batch script for automated email 12 89
    Union rows in array that have common elements 2 70
    Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
    In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (…
    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…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!

    794 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

    16 Experts available now in Live!

    Get 1:1 Help Now