0

python can communiate with each other via named pipes in my mac .but when i use nodejs to communicate with python ,it get wrong. My python code is:

import socket,os
s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
try:
    os.remove("/tmp/test.sock")
except OSError:
    pass
s.bind("/tmp/test.sock")
s.listen(1)
conn, addr = s.accept()
while 1:
    data = conn.recv(1024)
    if not data: break
    conn.send("server")
conn.close()

my nodejs code is:

var net = require('net');
var server = net.createServer(function(stream) {
  stream.on('data', function(c) {
    console.log('data:', c.toString());
  });
  stream.on('end', function() {
    server.close();
  });
});

server.listen('/tmp/test.sock');
var stream = net.connect('/tmp/test.sock');
stream.write('hello');
stream.end();
  • events.js:141 throw er; // Unhandled 'error' event ^ Error: listen EADDRINUSE /tmp/test.sock at Object.exports._errnoException (util.js:870:11) at exports._exceptionWithHostPort (util.js:893:20) at Server._listen2 (net.js:1221:19) at listen (net.js:1270:10) at Server.listen (net.js:1360:5) at Object. (/Users/chen-pc/pipecommunicate.js:12:8) at Module._compile (module.js:409:26) at Object.Module._extensions..js (module.js:416:10) at Module.load (module.js:343:32) at Function.Module._load (module.js:300:12) – Fang Cheney Dec 08 '16 at 12:47
  • 1
    You should paste the error in your question, not as an (unformatted) comment. – mscdex Dec 08 '16 at 12:48
  • EADDRINUSE: Your node server is trying to run on a port which is already being used. – Aman Gupta Dec 08 '16 at 12:58

0 Answers0