0

我对网页设计非常陌生,我正在尝试将 express 与 node.js 一起使用。

在以下代码中:

var app = express()
  , http = require('http')
  , server = http.createServer(app)
  , io = require('socket.io').listen(server);

http,server和io之间的关系/区别是什么?

4

1 回答 1

1

It's actually fairly simple:

  1. http uses app to handle incoming HTTP requests. Express (app) is acting on request event. This event is used to handle HTTP requests.
  2. 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.
于 2013-09-05T18:50:47.977 回答