Download Reference Manual
The Developer's Library for D
About Wiki Forums Source Search Contact

Simple Unix socket example

Moderators: larsivi kris

Posted: 11/03/08 08:57:46

Howdy,

I've been trying to setup some basic IPC between some D processes. I decided on trying Unix sockets, because I've done them in C# and Ruby. I can't seem to figure out how to do it in Tango/D. I've looked at the examples, tutorials, and reference, but only see references to TCP/UDP sockets. Here is what I have so far:

import tango.io.Stdout;

import tango.net.Socket;
import tango.net.ServerSocket;
import tango.net.SocketConduit;

int main() {
    Socket server = new Socket(AddressFamily.UNIX, 
                               SocketType.STREAM, 
                               ProtocolType.IP);

    while(true) {
        Socket client = server.accept();

        char[1024] buffer;
        client.receive(buffer);

        Stdout.format("The client said'{}'.", buffer);

        client.shutdown(SocketShutdown.BOTH);
        client.detach();
    }
    return 0;
}

It fails with invalid argument. Obviously I don't even give it the name of a file to attach to.

Can someone show me how to complete this? or perhaps an example of a higher level conduit?

Author Message

Posted: 11/03/08 09:13:20

Hi matt :)

You could try out what is presented in #1156. As noted there, we probably won't add this into Tango, but if you find it difficult to do what you want without hacking Tango, please let us know.

Posted: 11/04/08 16:26:50

Oh well. I tried using the UnixAddress? code from that ticket. But could not get it to work.

Looks like I will be using the network cluster stuff instead.

Thanks anyway