I've borrowed the code below from the Perl cookbook (Chap 17).

Started with TCP sockets (see links), but really want Unix domain (##URL REMOVED##) (as the clients/server will be on the same machine).

The INET version works fine, but converting the socket to Unix as shown means no input seems to arrive at the server.

Server (##URL REMOVED##)

use POSIX; use IO::Socket; use IO::Select; use Socket; use Fcntl; use Tie::RefHash; + $port = N; # change this at will + # Listen to port. #$server = IO::Socket::INET->new(LocalPort => $port, # Listen => 10 ) # or die "Can't make server socket: $@\n"; + unlink "/tmp/mysock"; $server = IO::Socket::UNIX->new(Local => "/tmp/mysock", Type => SOCK_STREAM, Listen => 5 ) or die "Failed to make socket: $!";
Client (##URL REMOVED##)
use IO::Socket; + #$socket = IO::Socket::INET->new(PeerAddr => "x.x.x.x", # PeerPort => "N", # Proto => "tcp", # Type => SOCK_STREAM) # or die "Couldn't connect to x.x.x.x :N : $@\n"; + $socket = IO::Socket::UNIX->new(PeerAddr => "/tmp/mysock", Type => SOCK_STREAM, Timeout => 10 ) or die $@;
Obviously I've obscured the actual machine ip/port.

Edited by Chady -- removed link to copyrighted material


In reply to Unix domain sockets problem by Anonymous Monk

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.