Hi Manfred, Please reply to list if it's a mailing list post - http://shlom.in/reply .
On Wed, 8 Jan 2014 11:42:45 +0100 Manfred Lotz <manfred.l...@arcor.de> wrote: > Hi there, > For test purposes I want to create a socket file. Something I could > list via ls -l. That's all I want to achieve. > > As I didn't find any utility to create a socket file my hope is that > Perl offers something to do this. > > Any idea? If by a socket file you mean a UNIX domain socket, then if unix-domain-socket-server.pl is: [CODE] #!/usr/bin/perl use strict; use warnings; use IO::Socket::UNIX; use File::Path qw(mkpath); my $dir = "$ENV{HOME}/tmp/unix-domain-socket-test"; mkpath($dir); my $server = IO::Socket::UNIX->new( Type => SOCK_STREAM(), Local => "$dir/foo.sock", Listen => 1, ); my $count = 1; while (my $conn = $server->accept()) { $conn->print("Hello " . ($count++) . "\n"); } [/CODE] and unix-domain-socket-client.pl is: [CODE] #!/usr/bin/perl use strict; use warnings; use IO::Socket::UNIX; my $client = IO::Socket::UNIX->new( Type => SOCK_STREAM(), Peer => "$ENV{HOME}/tmp/unix-domain-socket-test/foo.sock", ); my $contents = do { local $/; <$client>; }; print "Got <<$contents>>\n"; [/CODE] Then if I run: shlomif@telaviv1:~/tmp/unix-domain-socket-test$ perl \ ~/progs/perl/snippets/unix-domain-socket-server.pl I can do: [SHELL] shlomif@telaviv1:~/tmp/unix-domain-socket-test$ ls -l total 0 srwxr-xr-x 1 shlomif shlomif 0 Jan 8 13:11 foo.sock shlomif@telaviv1:~/tmp/unix-domain-socket-test$ perl ~/progs/perl/snippets/unix-domain-socket-client.pl Got <<Hello 1 >> shlomif@telaviv1:~/tmp/unix-domain-socket-test$ perl ~/progs/perl/snippets/unix-domain-socket-client.pl Got <<Hello 2 >> shlomif@telaviv1:~/tmp/unix-domain-socket-test$ perl ~/progs/perl/snippets/unix-domain-socket-client.pl Got <<Hello 3 >> shlomif@telaviv1:~/tmp/unix-domain-socket-test$ [/SHELL] You can find it here: https://github.com/shlomif/shlomif-perl-snippets You may wish to read http://perldoc.perl.org/IO/Socket/UNIX.html . Hope that helps and best regards, Shlomi Fish -- ----------------------------------------------------------------- Shlomi Fish http://www.shlomifish.org/ List of Networking Clients - http://shlom.in/net-clients “My only boss is God. And Chuck Norris who is his boss.” — http://www.shlomifish.org/humour/bits/facts/Chuck-Norris/ Please reply to list if it's a mailing list post - http://shlom.in/reply . -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/