-
-
Save dshaw/9f93cdcd3a77b9142e51 to your computer and use it in GitHub Desktop.
net.js UNIX domain socket issue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var net = require('net'); | |
var path = '/tmp/echo.sock'; | |
var server = net.createServer(function(c) { | |
console.log('server connected'); | |
c.on('end', function() { | |
console.log('server disconnected'); | |
}); | |
c.write('hello\r\n'); | |
c.pipe(c); | |
}); | |
server.listen(path, function() { | |
console.log('server bound on %s', path); | |
}); |
Here's a nice little optimization from @kitcambridge, removing the stat call and sync:
var net = require('net');
var fs = require('fs');
var path = '/tmp/echo.sock';
fs.unlink(path, function () {
var server = net.createServer(function(c) {
console.log('server connected');
c.on('end', function() {
console.log('server disconnected');
});
c.write('hello\r\n');
c.pipe(c);
});
server.listen(path, function() {
console.log('server bound on %s', path);
});
});
And now?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This issue effects every REPL that's attached to my production code! A workaround for now would be to unlink (remove) the "file":