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 (egSOCK_STREAMorSOCK_DGRAM)Localβ Path to local fifoPeerβ Path to peer fifoListenβ 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 endpeerpath()β Returns the pathname to the fifo at the peer end
two methods, both serving exactly. periodt. π₯
π SEE ALSO π
SocketIO::Socket
π AUTHOR π
Graham Barr. Currently maintained by the Perl Porters. Please report all bugs at https://github.com/Perl/perl5/issues. π
π COPYRIGHT π
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