I'm new to node.js, so i have some questions about connect framework and socket.io:

  • What's different? i'm confused about it.
  • Should i use connect fw with socket.io or just use socket.io?
有帮助吗?

解决方案

The Connect module is a web application framework, while Socket.IO is a realtime transport module. You would use one to create web applications, and the other for bidirectional communication between a server and a client.

Here's a few of the things the modules can do:

Connect:

  • service static files and pages
  • provide cookie-based sessions
  • accept file uploads
  • handle HTTP verbs (GET/POST/PUT/DELETE)

Socket.IO:

  • authorize connecting sockets
  • send data between server and client with multiple transports
  • supports (WebSocket/XHR long-polling/flashsocket/JSONP)

So if you wanted to create a website, you would use Connect. However, if you wanted that website to have something such as realtime chat capability, then you would use Socket.IO.

Whether you should use one module or the other, or use them together, is dependent on your application requirements.

其他提示

Connect is special module which can provide scalable functionality. You can just add features as middleware. It reminds some kind of configuration of your project, it just simplify routine.

var app = connect()
  .use(connect.logger('dev'))
  .use(connect.static('public'))
  .use(connect.bodyParser())
 .listen(3000);

After adding this for example you can access features which connect provide. For example you can have logging (method url and seconds) for each application activity, or add session support, easy with one line of code. The same way you can add socket support I suppose.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top