mirror of https://github.com/lukechilds/node.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
1.1 KiB
48 lines
1.1 KiB
process.Buffer.prototype.toString = function () {
|
|
return this.utf8Slice(0, this.length);
|
|
};
|
|
|
|
var sys = require("sys");
|
|
var net = require("./lib/net");
|
|
|
|
var server = new net.Server(function (socket) {
|
|
sys.puts("connection (" + socket.fd + "): "
|
|
+ socket.remoteAddress
|
|
+ " port "
|
|
+ socket.remotePort
|
|
);
|
|
sys.puts("server fd: " + server.fd);
|
|
|
|
socket.addListener("data", function (b) {
|
|
socket.send("pong ascii\r\n", "ascii");
|
|
socket.send(b);
|
|
socket.send("pong utf8\r\n", "utf8");
|
|
});
|
|
|
|
socket.addListener("eof", function () {
|
|
sys.puts("server peer eof");
|
|
socket.close();
|
|
});
|
|
|
|
socket.addListener('drain', function () {
|
|
sys.puts("server-side socket drain");
|
|
});
|
|
});
|
|
server.listen(8000);
|
|
sys.puts("server fd: " + server.fd);
|
|
|
|
|
|
var c = net.createConnection(8000);
|
|
c.addListener('connect', function () {
|
|
sys.puts("!!!client connected");
|
|
c.send("hello\n");
|
|
});
|
|
|
|
c.addListener('drain', function () {
|
|
sys.puts("!!!client drain");
|
|
});
|
|
|
|
c.addListener('receive', function (d) {
|
|
sys.puts("!!!client got: " + JSON.stringify(d.toString()));
|
|
});
|
|
|
|
|