reading from named pipe (windows)

669 views
Skip to first unread message

tomam...@gmail.com

unread,
Feb 13, 2015, 2:53:00 PM2/13/15
to nwjs-g...@googlegroups.com
Hi all,

I am running into an issue trying to read from a named pipe in NW on Windows. I have the following code that can read from a named pipe as a plain node.js application:

var net = require('net');
var conn = net.createConnection('\\\\.\\pipe\\test_pipe');
conn.on('data', function(data) {
    console.log(data + '\n\n');
})

However, when I run insert this into a script in my NW app, I get a ENOENT error. This means that the file doesn't exist - it can't find the named pipe. Is this due to some sandbox restrictions with NW? Is there any way for me to change these settings so that it can read a named pipe?

Thanks,
Thomas 

blas...@gmail.com

unread,
Jul 13, 2015, 12:14:27 PM7/13/15
to nwjs-g...@googlegroups.com, tomam...@gmail.com
Going to add here because this was the first result i found, and it unfortunately didn't help, here's the code I'm using to create my socket listener for unix/linux and Windows

var os = require('os');
var sock = (process.platform.match(/win32/ig) ? "\\\\.\\pipe\\mysocket" : os.tmpDir()+'/mysocket.sock')

var net = require('net');
server = net.createServer(function(stream) {
    stream.on('data', function(c) {
        console.log("Socket Data: "+c.toString())
    })
});
server.listen(sock);

You might have to unlink the socket on unix/linux/darwin based systems
Reply all
Reply to author
Forward
0 new messages