首页 Node.js核心模块手册

参数说明


on(event, callback)
event        事件名称
callback(    回调函数
  e             参数,根据不同事件返回不同参数(参考:事件列表)
)

事件列表


事件 示例 描述
connent client.on("connent", function(){}) 客户端调用 connent 方法时触发
data client.on("data", function(data){}) 接收到服务器发送的数据时触发,数据是Buffer类型,需用toString()转换,或在使用socket.setEncoding("utf8")指定
end client.on("end", function(){}) 关闭连接时触发
error

client.on("error", function(e){})

参数:

e.code=="EADDRINUSE" 服务端强制断开连接

连接中,服务器强制断开连接时发生错误