1IO::Socket::UNIX(3pm) Perl Programmers Reference Guide IO::Socket::UNIX(3pm)
2
3
4
6 IO::Socket::UNIX - Object interface for AF_UNIX domain sockets
7
9 use IO::Socket::UNIX;
10
11 my $SOCK_PATH = "$ENV{HOME}/unix-domain-socket-test.sock";
12
13 # Server:
14 my $server = IO::Socket::UNIX->new(
15 Type => SOCK_STREAM(),
16 Local => $SOCK_PATH,
17 Listen => 1,
18 );
19
20 my $count = 1;
21 while (my $conn = $server->accept()) {
22 $conn->print("Hello " . ($count++) . "\n");
23 }
24
25 # Client:
26 my $client = IO::Socket::UNIX->new(
27 Type => SOCK_STREAM(),
28 Peer => $SOCK_PATH,
29 );
30
31 # Now read and write from $client
32
34 "IO::Socket::UNIX" provides an object interface to creating and using
35 sockets in the AF_UNIX domain. It is built upon the IO::Socket
36 interface and inherits all the methods defined by IO::Socket.
37
39 new ( [ARGS] )
40 Creates an "IO::Socket::UNIX" object, which is a reference to a
41 newly created symbol (see the "Symbol" package). "new" optionally
42 takes arguments, these arguments are in key-value pairs.
43
44 In addition to the key-value pairs accepted by IO::Socket,
45 "IO::Socket::UNIX" provides.
46
47 Type Type of socket (eg SOCK_STREAM or SOCK_DGRAM)
48 Local Path to local fifo
49 Peer Path to peer fifo
50 Listen Queue size for listen
51
52 If the constructor is only passed a single argument, it is assumed
53 to be a "Peer" specification.
54
55 If the "Listen" argument is given, but false, the queue size will
56 be set to 5.
57
58 If the constructor fails it will return "undef" and set the
59 $IO::Socket::errstr package variable to contain an error message.
60
61 $sock = IO::Socket::UNIX->new(...)
62 or die "Cannot create socket - $IO::Socket::errstr\n";
63
64 For legacy reasons the error message is also set into the global $@
65 variable, and you may still find older code which looks here
66 instead.
67
68 $sock = IO::Socket::UNIX->new(...)
69 or die "Cannot create socket - $@\n";
70
72 hostpath()
73 Returns the pathname to the fifo at the local end
74
75 peerpath()
76 Returns the pathanme to the fifo at the peer end
77
79 Socket, IO::Socket
80
82 Graham Barr. Currently maintained by the Perl Porters. Please report
83 all bugs at <https://github.com/Perl/perl5/issues>.
84
86 Copyright (c) 1996-8 Graham Barr <gbarr@pobox.com>. All rights
87 reserved. This program is free software; you can redistribute it
88 and/or modify it under the same terms as Perl itself.
89
90
91
92perl v5.36.3 2023-11-30 IO::Socket::UNIX(3pm)