2009-12-17 08:37:25 +01:00
|
|
|
process.Buffer.prototype.toString = function () {
|
|
|
|
return this.utf8Slice(0, this.length);
|
|
|
|
};
|
|
|
|
|
|
|
|
var sys = require("sys");
|
|
|
|
var net = require("./lib/net");
|
|
|
|
|
2009-12-28 16:42:48 +01:00
|
|
|
var server = new net.Server(function (socket) {
|
|
|
|
sys.puts("connection (" + socket.fd + "): "
|
|
|
|
+ socket.remoteAddress
|
2009-12-17 08:37:25 +01:00
|
|
|
+ " port "
|
2009-12-28 16:42:48 +01:00
|
|
|
+ socket.remotePort
|
2009-12-17 08:37:25 +01:00
|
|
|
);
|
|
|
|
sys.puts("server fd: " + server.fd);
|
|
|
|
|
2009-12-28 16:42:48 +01:00
|
|
|
socket.addListener("data", function (b) {
|
|
|
|
socket.send("pong ascii\r\n", "ascii");
|
|
|
|
socket.send(b);
|
|
|
|
socket.send("pong utf8\r\n", "utf8");
|
2009-12-30 20:32:07 +01:00
|
|
|
if (/^quit/.test(b)) {
|
|
|
|
socket.close();
|
|
|
|
server.close();
|
|
|
|
}
|
2009-12-17 08:37:25 +01:00
|
|
|
});
|
2009-12-17 09:31:10 +01:00
|
|
|
|
2009-12-28 16:42:48 +01:00
|
|
|
socket.addListener("eof", function () {
|
|
|
|
sys.puts("server peer eof");
|
|
|
|
socket.close();
|
2009-12-18 14:52:02 +01:00
|
|
|
});
|
|
|
|
|
2009-12-28 16:42:48 +01:00
|
|
|
socket.addListener('drain', function () {
|
|
|
|
sys.puts("server-side socket drain");
|
2009-12-17 09:31:10 +01:00
|
|
|
});
|
2009-12-17 08:37:25 +01:00
|
|
|
});
|
2009-12-17 09:31:10 +01:00
|
|
|
|
2009-12-30 20:32:07 +01:00
|
|
|
server.addListener("listening", function () {
|
|
|
|
var c = net.createConnection("/tmp/node.sock");
|
|
|
|
c.addListener('connect', function () {
|
|
|
|
sys.puts("!!!client connected");
|
|
|
|
c.send("hello\n");
|
|
|
|
});
|
2009-12-17 09:31:10 +01:00
|
|
|
|
2009-12-30 20:32:07 +01:00
|
|
|
c.addListener('drain', function () {
|
|
|
|
sys.puts("!!!client drain");
|
|
|
|
});
|
2009-12-17 09:31:10 +01:00
|
|
|
|
2009-12-30 20:32:07 +01:00
|
|
|
c.addListener('data', function (d) {
|
|
|
|
sys.puts("!!!client got: " + JSON.stringify(d.toString()));
|
|
|
|
c.close();
|
|
|
|
});
|
2009-12-17 09:31:10 +01:00
|
|
|
|
2009-12-30 20:32:07 +01:00
|
|
|
c.addListener('eof', function (d) {
|
|
|
|
sys.puts("!!!client eof");
|
|
|
|
});
|
2009-12-18 14:52:02 +01:00
|
|
|
});
|
2009-12-17 09:31:10 +01:00
|
|
|
|
2009-12-30 20:51:43 +01:00
|
|
|
server.listen("/tmp/node.sock");
|
|
|
|
sys.puts("server fd: " + server.fd);
|