如果不用socket.io
想深入的学习在nodejs用socket和客户端通信 如果不引用额外的包 我该学习哪些东西,来实现这样的功能???
3 回复
net,http,dgram,websocket
let net = require(‘net’);
let server = net.createServer(function (socket) {
socket.write("hello, this is server");
socket.on("data", function(data) {
console.log("server : ", data.toString());
});
socket.on("close", function() {
console.log("server : client is disconnect")
})
});
server.listen(“3001”, “127.0.0.1”, function () { console.log(“server : listening start”) })
@wtcsy Node的官网有示例: https://nodejs.org/dist/latest-v6.x/docs/api/http.html 见 Event: ‘upgrade’