What does addListener do in node.js?
Posted
by Jeffrey
on Stack Overflow
See other posts from Stack Overflow
or by Jeffrey
Published on 2010-04-29T11:35:48Z
Indexed on
2010/04/29
11:37 UTC
Read the original article
Hit count: 187
I am trying to understand the purpose of addListener in node.js. Can someone explain please? Thanks! A simple example would be:
var tcp = require('tcp');
var server = tcp.createServer(function (socket) {
socket.setEncoding("utf8");
socket.addListener("connect", function () {
socket.write("hello\r\n");
});
socket.addListener("data", function (data) {
socket.write(data);
});
socket.addListener("end", function () {
socket.write("goodbye\r\n");
socket.end();
});
});
server.listen(7000, "localhost");
© Stack Overflow or respective owner