我对网页设计非常陌生,我正在尝试将 express 与 node.js 一起使用。
在以下代码中:
var app = express()
, http = require('http')
, server = http.createServer(app)
, io = require('socket.io').listen(server);
http,server和io之间的关系/区别是什么?
It's actually fairly simple:
http
uses app
to handle incoming HTTP requests. Express (app) is acting on request
event. This event is used to handle HTTP requests.io
attaches itself to the connection
event of HTTP server. I believe it's implemented here. connection
event is emited whenever a new TCP connection is established, thus it's a good fit for web sockets.