简体   繁体   English

我应该为我的nodejs应用程序使用socket.io吗?

[英]Should I be using socket.io for my nodejs application?

I am learning HTML5 and doing so by building a simple chatroom using Express, PassportJS, Mongoose/MongoDB, connect-mongoose, NowJS. 我正在学习HTML5,并通过使用Express,PassportJS,Mongoose / MongoDB,connect-mongoose,NowJS构建一个简单的聊天室来进行学习。

Everything works perfectly, except for one big problem: I am having trouble authenticating NowJS. 除一个大问题外,一切都正常运行:我在验证NowJS时遇到问题。

The usual way of doing this is to read the "this.user.cookie" property server-side and parse the string. 这样做的通常方法是在服务器端读取“ this.user.cookie”属性并解析该字符串。 However, for some reason, cookies is not being sent back to the server. 但是,由于某些原因,cookie不会被发送回服务器。 (details here: NowJS cookie field in this.user is empty ) After a lot of googling, I think there are no alternative, secured, way for me to authenticate NowJS connections/clients. (详细信息: this.user中的NowJS cookie字段为空 )经过大量的搜索之后,我认为没有其他替代方法可以保护我对NowJS连接/客户端的身份验证。

Question

I am thinking of stripping all of NowJS out of my web app, and using socket.io directly. 我正在考虑从我的Web应用程序中剥离所有NowJS,并直接使用socket.io。 Is socket.io easy with work with? socket.io易于使用吗? Would I lose key functionality if I switch to socket.io, instead of using NowJS? 如果我切换到socket.io而不使用NowJS,会失去关键功能吗?

Can I use socket.io to: 我可以使用socket.io来:

1) Call server-side functions? 1)调用服务器端功能?

2) Share server-side variables with the client? 2)与客户端共享服务器端变量?

Socket.io does not share variables or allow you to call server side functions. Socket.io不共享变量,也不允许您调用服务器端函数。 It allows you to bind and emit events on the client side and server side. 它允许您在客户端和服务器端绑定并发出事件。

As for your cookie not being sent, its most likely that its being considered a cors, cross domain request, this can happen if your using a different port for socket.io then the http server that set the cookie. 至于您的cookie没有被发送,很可能是因为它被视为一个cors跨域请求,如果您对socket.io使用了另一个端口来设置cookie,则可能发生这种情况。

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

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