E
Erik Anderson
I'm trying to implement IPC using IO::Socket::UNIX, but have come into
significant difficulty. I've searched groups.google.com, and have been
able to find very few examples of the proper use of IO::Socket::UNIX.
I have written a very simple client and server system to test this. The
code is below. The client sends some data to the server, which should
display it...it's not working though. Any ideas?
Client Code:
--------------------
#!/usr/bin/perl
use IO::Handle;
use IO::Socket;
$socket = IO::Socket::UNIX->new( Peer => "/sckt",
Type => SOCK_STREAM,
Timeout => 10 ) or die "$!\n$@";
$socket->autoflush(1);
$num=0;
while(1) {
print $socket "$num";
$socket->flush();
$num++;
sleep(2);
}
exit;
--------------------
Server code:
--------------------
#!/usr/bin/perl
use IO::Handle;
use IO::Socket;
unlink "/sckt";
my $Server = IO::Socket::UNIX->new( Local => "/sckt",
Type => SOCK_STREAM,
Listen => 5
) or die $@;
while($session = $Server->accept) {
chomp($line = <$session>);
print "From client: " . $line . "\n";
$Server->flush();
sleep(1);
}
exit;
significant difficulty. I've searched groups.google.com, and have been
able to find very few examples of the proper use of IO::Socket::UNIX.
I have written a very simple client and server system to test this. The
code is below. The client sends some data to the server, which should
display it...it's not working though. Any ideas?
Client Code:
--------------------
#!/usr/bin/perl
use IO::Handle;
use IO::Socket;
$socket = IO::Socket::UNIX->new( Peer => "/sckt",
Type => SOCK_STREAM,
Timeout => 10 ) or die "$!\n$@";
$socket->autoflush(1);
$num=0;
while(1) {
print $socket "$num";
$socket->flush();
$num++;
sleep(2);
}
exit;
--------------------
Server code:
--------------------
#!/usr/bin/perl
use IO::Handle;
use IO::Socket;
unlink "/sckt";
my $Server = IO::Socket::UNIX->new( Local => "/sckt",
Type => SOCK_STREAM,
Listen => 5
) or die $@;
while($session = $Server->accept) {
chomp($line = <$session>);
print "From client: " . $line . "\n";
$Server->flush();
sleep(1);
}
exit;