Unix sockets on Windows and Node.js

I have a Node.js application using Unix sockets which works on Linux, but I’m trying to make it work on Windows.

My socket has a name similar to C:\PathTo\socket.sock. The following code seems to work:

let addr = "C:\\PathTo\\socket.sock" in
let fd = Unix.socket PF_UNIX SOCK_STREAM 0 in
Unix.bind fd (ADDR_UNIX addr)

I can call Unix.listen and Unix.accept, and it seems to work and wait for clients.

However, when I try to connect from a Node.js client using that same address, I get an EACCES error, which led me to this StackOverflow question. It mentions part of the Node.js documentation:

On Windows, the local domain is implemented using a named pipe. The path must refer to an entry in \\?\pipe\ or \\.\pipe\.

I tried adding that prefix to the JS code that connects to the socket, but then I get a ENOENT error. And if I add the same prefix to the OCaml socket address, it fails with ENETDOWN when trying to do the bind.

Are there examples of such usage in Windows that work? I’m having a hard time identifying if the problem is related to Node.js, to OCaml’s implementation of Unix sockets, or some other Windows issue.

Note that Unix domain sockets came to Windows only recently (see AF_UNIX comes to Windows - Windows Command Line) and in OCaml, since 4.14 (see Support Unix domain sockets and emulate socketpair on Windows by MisterDA · Pull Request #10192 · ocaml/ocaml · GitHub).

My feeling from reading the Node.js documentation that you quoted is that the Node runtime emulates Unix domain sockets using named pipes; but this probably won’t work with “true” Unix sockets as implemented by the OCaml runtime.

Cheers,
Nicolas