Blessings upon ye Monks.
I'm trying to do a conversation between a client and server using unix domain sockets. I can do one way communication, but not two-way. I haven't been able to find any docs specific to unix domain sockets that show a two way conversation. The docs about other sockets (tcp/ip, for instance) seem to imply you can just read and write to the same socket and it will "just work". I've found examples of one-way conversations, but no two way conversations.
So! My question to you monks is, does anyone have an example of a two way conversation using unix domain sockets that they could point me to? Or, if you know of something special I need to do (select?), that would also be great.
Update:
Now with example code!
The Server
#! /usr/bin/perl -w -T %ENV = (); $ENV{PATH} = "/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/ +sbin"; use strict; use Socket; my $socket_path = '/tmp/wibble'; my $sock_addr = sockaddr_un($socket_path); socket(my $server, PF_UNIX,SOCK_STREAM,0) || die "socket: $!"; unlink($socket_path); bind($server,$sock_addr) || die "bind: $!"; listen($server,SOMAXCONN) || die "listen: $!"; accept(my $client,$server); print 'Client Sez "'.<$client>."\"\n"; print $client "Same to ya, fella\n";
The Client
#! /usr/bin/perl -w -T %ENV = (); $ENV{PATH} = "/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/ +sbin"; use Socket; use strict; my $name = '/tmp/wibble'; my $sock_addr = sockaddr_un($name); socket(my $server, PF_UNIX,SOCK_STREAM,0) || die "socket: $!"; connect($server, $sock_addr) || die "connect: $!"; print $server "Wibble"; # if you comment this out, the 1 way conversation will work print "Server Sez ".<$server>."\n";
Note, that if you comment out the bit in the client where it attempts to reply to the server, the one way communication will work. If you leave it there, no communication works at all.
Thanks!
--Pileofrogs
In reply to Unix Domain Sockets by pileofrogs
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |