我正试图学习如何使用套接字在同一台机器上的进程之间进行通信。我开始用Perl的食谱采取这种简单的测试程序:如何创建一个Unix域套接字?
use feature qw(say);
use strict;
use warnings;
use IO::Socket;
my $socket_file = 'mysocket';
if (-e $socket_file) {
unlink $socket_file or die "Could not delete socket file '$socket_file': $!";
}
my $sock = IO::Socket::UNIX->new(
LocalAddr => $socket_file,
Type => SOCK_STREAM,
Listen => 5, # listen to max 5 connections
) or die "Could not create socket: '[email protected]'";
say "Created socket successfully..";
sleep 1;
close $sock;
say "Closed socket..";
exit;
输出是:
Could not create socket: '' at ./test.pl line 10.
所以现在的问题是:为什么IO::Socket::UNIX->new()
失败,为什么它没有设置[email protected]
当它失败?
似乎工作,如果我将'LocalAddr'改为'Local' .. –