IO::Socket::UNIX(3pm)
π IO::Socket::UNIX π
hey bestie! this is the IO::Socket::UNIX(3pm) page from the Perl Programmers Reference Guide. it's giving Unix socket excellence, no cap π«Άβ¨
πΈ NAME πΈ
IO::Socket::UNIX β object interface for AF_UNIX domain sockets. periodt π
π¦ SYNOPSIS π¦
okay so here's the whole vibe in code, fr fr:
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
π DESCRIPTION π
IO::Socket::UNIX gives you an object interface for creating and using sockets in the AF_UNIX domain. it's built on top of the IO::Socket interface, so it inherits every single method defined by IO::Socket. iykyk β¨
π CONSTRUCTOR π
π new ( [ARGS] ) π
this creates an IO::Socket::UNIX object, and that object is a reference to a newly created symbol (peep the Symbol package for that one). new can take arguments, and those arguments are in key-value pairs. slay π«Ά
on top of the key-value pairs IO::Socket already accepts, IO::Socket::UNIX brings these:
Typeβ what kind of socket it is (likeSOCK_STREAMorSOCK_DGRAM) π₯Localβ path to the local fifo πPeerβ path to the peer fifo πΈListenβ queue size for listen π
if you only pass a single argument to the constructor, it's assumed to be a Peer specification. lowkey simple π¦
if the Listen argument is given but false, the queue size gets set to 5. no cap π
if the constructor fails, it returns undef and sets the $IO::Socket::errstr package variable to contain an error message. not me crying in error handling π
$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 here instead. retro behavior, honestly π°οΈ
$sock = IO::Socket::UNIX->new(...)
or die "Cannot create socket - $@\n";
β¨ METHODS β¨
π hostpath() π
returns the pathname to the fifo at the local end. that's it, that's the method β¨
π peerpath() π
returns the pathanme β yep, the page says it like that, typo chic β to the fifo at the peer end. iconic π
π₯ SEE ALSO π₯
Socket, IO::Socket β go read those too, bestie π
π AUTHOR π
Graham Barr. Currently maintained by the Perl Porters. Please report all bugs at https://github.com/Perl/perl5/issues. they're iconic for keeping it alive πβ¨
π 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. π
mwah π β this page is from perl v5.42.3, dated 2026-11-03, and it's the IO::Socket::UNIX(3pm) manual. byeee π«Άβ¨
π¦ where this page comes from
- alpine 3.24: perl-doc 5.42.3-r0 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms