Abstract sockets (linux)
Ali Çehreli via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu Jun 25 12:47:37 PDT 2015
On 06/25/2015 08:56 AM, freeman wrote:
> I am having trouble using abstract sockets on Linux.
>
> Here is sample python code that works, which works:
> ptm_sockname = "\0/var/run/ptmd.socket"
> sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
> sock.connect(ptm_sockname)
> sock.setblocking(1)
> sock.sendall('get-status detail')
>
> Similar code in D, which does not work:
> string socket_name = "\0/var/run/ptmd.socket";
> auto address = new UnixAddress(socket_name);
> auto sock = new Socket(AddressFamily.UNIX, SocketType.STREAM);
> scope(exit) sock.close();
> sock.blocking = true;
> sock.connect(address);
> sock.send("get-status detail");
>
> This is the equivalent with socat, which works:
> $ echo "get-status detail" | socat -
> ABSTRACT-CLIENT:/var/run/ptmd.socket
>
> My test D program exits on connect:
> std.socket.SocketOSException at runtime/phobos/std/socket.d(2674): Unable
> to connect socket: Connection refused
>
> Any pointers?
I've found an old example of mine, which uses abstract sockets.
Apparently, it was a concurrency experiment as well. Just translated
from Turkish to English:
http://ddili.org/ornek_kod/client_server.d
One difference I see is that mine doesn't set blocking. You can use it
like this:
1) Start it as a server:
./deneme --role=server
2) Start as many clients as needed:
./deneme --role=client
Ali
P.S. And here is the original Turkish version:
http://ddili.org/ornek_kod/istemci_sunucu.d
More information about the Digitalmars-d-learn
mailing list