简体   繁体   English

socket.io的含义是监听快递服务器吗?

[英]Meaning of socket.io listen a express server?

I am reading socket.io's how to, this follow code I can not understand : 我正在读socket.io的方法,这个跟着代码我无法理解:

Server (app.js) 服务器(app.js)

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

server.listen(80);

what is the meaning of io = require('socket.io').listen(server); io = require('socket.io').listen(server);是什么意思io = require('socket.io').listen(server); , Is it just use same configurations with socket.io and express? ,它是否只使用与socket.io和express相同的配置?

The listen function takes as argument an http event handler such as the ones you get from http.Server (it can also accept a port, in which case the listen functions creates the http server ). listen函数将http事件处理程序作为参数,例如从http.Server获取的处理程序(它也可以接受端口,在这种情况下, listen函数创建http服务器 )。

The http.createServer function creates an http Server from a request listener. http.createServer函数从请求侦听器创建http服务器。 And that's what's an express application : a request listener, as can be seen here : 这就是是一个Express应用程序:请求监听器,可以看出这里

function createApplication() {
  var app = function(req, res, next) {
    app.handle(req, res, next);
  };
  ...
  return app;
}

Of course you don't need express to use socket.io, you may simply pass to listen a port or any instance of http.Server . 当然你不需要快递来使用socket.io,你可以简单地传递来listen端口或http.Server任何实例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM