IO::SOCKET::UNIX(3perl)

πŸ’– IO::Socket::UNIX β€” bestie edition πŸ’–

okay so you found the IO::Socket::UNIX page, which lives in the perl manual, section 3perl, of the Perl Programmers Reference Guide. it's about AF_UNIX domain sockets and it's honestly iconic. let's go πŸ¦‹


✨ NAME ✨

IO::Socket::UNIX β€” object interface for AF_UNIX domain sockets πŸ’…


🌸 SYNOPSIS 🌸

use IO::Socket::UNIX;

my $SOCK_PATH = "$ENV{HOME}/unix-domain-socket-test.sock";

# Server:
my $server = IO::Socket::UNIX->new(
    Type => SOCK_STREAM(),
    Local => $SOCK_PATH,
    Listen => 1,
);

my $count = 1;
while (my $conn = $server->accept()) {
    $conn->print("Hello " . ($count++) . "\n");
}

# Client:
my $client = IO::Socket::UNIX->new(
    Type => SOCK_STREAM(),
    Peer => $SOCK_PATH,
);

# Now read and write from $client

like… a whole server AND a whole client in one code block?? we love a two-for-one 🫢


πŸŽ€ DESCRIPTION πŸŽ€

so basically, IO::Socket::UNIX hands you an object interface for creating and using sockets in the AF_UNIX domain. it's built on top of the IO::Socket interface, and it inherits every single method that IO::Socket defines. no cap. πŸ‘‘


πŸ’… CONSTRUCTOR πŸ’…

new ( [ARGS] )

creates an IO::Socket::UNIX object, which is a reference to a newly created symbol (peep the Symbol package for that). new optionally takes arguments, and those arguments come in key-value pairs.

on top of the key-value pairs that IO::Socket already accepts, IO::Socket::UNIX brings its own little set:

  • Type β€” Type of socket (eg SOCK_STREAM or SOCK_DGRAM)
  • Local β€” Path to local fifo
  • Peer β€” Path to peer fifo
  • Listen β€” Queue size for listen

if you pass the constructor only a single argument, it gets assumed to be a Peer specification. that's the vibe check right there ✨

if the Listen argument is given, but it's false, then the queue size gets set to 5. noted. πŸ“

if the constructor fails, it returns undef and sets the $IO::Socket::errstr package variable to contain an error message.

$sock = IO::Socket::UNIX->new(...)
    or die "Cannot create socket - $IO::Socket::errstr\n";
for legacy reasons the error message is also set into the global $@ variable, and you may still find older code which looks there instead. ancient. historical. still real.
$sock = IO::Socket::UNIX->new(...)
    or die "Cannot create socket - $@\n";

🧚 METHODS 🧚

  • hostpath() β€” Returns the pathname to the fifo at the local end
  • peerpath() β€” Returns the pathname to the fifo at the peer end

two methods, both serving exactly. periodt. πŸ”₯


🌈 SEE ALSO 🌈

  • Socket
  • IO::Socket

πŸ‘‘ AUTHOR πŸ‘‘

Graham Barr. Currently maintained by the Perl Porters. Please report all bugs at https://github.com/Perl/perl5/issues. πŸ›


Copyright (c) 1996-8 Graham Barr gbarr@pobox.com. All rights reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.


okay that's the whole page bestie, go make some sockets πŸ“

and for the sign-off β€” this was perl v5.44.0, dated 2026-10-17, page IO::Socket::UNIX(3perl). slay, stay hydrated, and close your file descriptors πŸ’–βœ¨

πŸ“¦ where this page comes from
  • arch rolling: perl 5.44.0-1 Β· Artistic-1.0-Perl AND GPL-1.0-or-later
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms