简体   繁体   中英

Node server and WS server running side by side?

I'm really new to Node.js and have been wondering something. I'm trying to build a simple chat room application as a way of teaching myself how this all works.

The way I see it working is that I have a Node http server which serves the pages of my site (homepage, login, chat screen etc) and then I have a WS server which accepts short messages to relay to all connected users.

The thing is I can't work out if this is the correct way to approach this. Is it possible to authenticate users on the Node server and know that they have been authenticated on the WS server? Can they share some kind of session?

Any help is appeciated!

You don't mention what you're using to implement a WebSocket server, so I'll assume you're using socket.io . (If you're not, you should.)

You can use the socket.io handshake process to access the HTTP session state.

If you're using Express (once again, highly recommended), it's easy to tie the two together .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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