简体   繁体   English

Express.io上的检测连接

[英]Detection connections on Express.io

I know this has been discussed here, but I just can't make it work. 我知道这里已经讨论过了,但是我无法使其正常工作。 The documentation in Express.io is quite difused. Express.io中的文档非常混乱。

I have a running server and I want to set an event when someone access to it. 我有一台正在运行的服务器,我想在有人访问它时设置一个事件。 This is my code for now: 这是我现在的代码:

var express = require('express.io');
var io = require("socket.io").listen(https);
...
var app = express();

app = require('express.io')();
app.https(options).io();

app.io.route('connect', function (req) {
   console.log(req);
      });

And it's not working.. it just doesn't detect any new connections. 而且它不起作用..它只是没有检测到任何新的连接。 Any help here? 这里有什么帮助吗?

You can not connect to the server because you forgot to invoke the listen method. 您无法连接到服务器,因为您忘记了调用listen方法。 You also did not define a request handler, so you can not connect with an ordinary http(s) request. 您也没有定义请求处理程序,因此无法连接普通的http(s)请求。

You defined an IO.route, but to send an event you need the socket.io lib on the client side. 您定义了IO.route,但是要发送事件,则需要客户端上的socket.io lib。 There are examples on the git hub express.io side. git hub express.io上有一些示例。 For better understanding I would suggest that, you should read the Intro-Documentation of express (not express.io) to understand, what a normal http (get, post, pull, ...) route is and how to start the server. 为了更好地理解,我建议您阅读express (不是express.io)的简介文档,以了解什么是正常的http(get,post,pull,...)路由以及如何启动服务器。

Yo do not need the explicit require and listen call of the socket.io lib, express.io encapsulates it. 不需要socket.io库的显式require和listen调用,express.io将其封装。

Missing line is 缺少行是

app.listen(7076); // port = 7076 can be changed by your needs

If you want to add an http get route use something like: 如果要添加http获取路由,请使用类似以下内容的方法:

app.get('/mypage', function(req, res) 
{
   res.send("my Page content");
})

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

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