简体   繁体   中英

Node.js independent socket sessions

I am quite new to using Node.js so please excuse my ignorance :)

Right now I have a web app which uses Node/Angular/Express in order to call C++ functions from a DLL on the server, and return the results to the client. However, I need the app to support multiple users.

The C++ server function I am calling returns a result based on a global object defined in the DLL (which can be modified). The problem is that when there are multiple clients accessing the web app, modifying the global object in one session effects the object being accessed in other sessions.

Example:

  • x is an object in the C++ DLL on the server
  • User #1 sets x to 5
  • Server returns 5 to User #1
  • User #2 sets x to 8
  • Server returns 8 to User #2
  • User #1 asks for x value
  • Server returns 8 to User#1 ( Would like 5 to be returned instead , since that's the latest value of x from User #1's perspective).

My assumption is that I should be using something like Socket.IO (similar to the basic tutorial http://socket.io/get-started/chat/ ). This is able to indicate when a user connects to the app, but it's not able keep the sessions independent from the user's perspective.

Any thoughts on how to go about keeping these sessions independent? Thanks!

This is not a node.js problem. node.js can do sessions just fine (express-session is a very popular way to implement sessions using express and node.js).

This sounds like you have a DLL that supports only a single user at a time which really isn't appropriate for multi-user server usage.

Though there are very ugly ways to work around that (such as launching a cached and aged separate child process for each user so each child process has its own separate loaded copy of the DLL), really what you need is a DLL that doesn't keep a single user's state in global memory so it can be used on behalf of multiple users.

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