简体   繁体   English

Node.js独立套接字会话

[英]Node.js independent socket sessions

I am quite new to using Node.js so please excuse my ignorance :) 我对使用Node.js很陌生,所以请原谅我的无知:)

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. 现在,我有一个Web应用程序,它使用Node / Angular / Express以便从服务器上的DLL调用C ++函数,并将结果返回给客户端。 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). 我正在调用的C ++服务器函数返回基于DLL中定义的全局对象的结果(可以修改)。 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. 问题在于,当有多个客户端访问Web应用程序时,在一个会话中修改全局对象会影响在其他会话中访问的对象。

Example: 例:

  • x is an object in the C++ DLL on the server x是服务器上C ++ DLL中的对象
  • User #1 sets x to 5 用户#1将x设置为5
  • Server returns 5 to User #1 服务器将5返回给用户#1
  • User #2 sets x to 8 用户#2将x设置为8
  • Server returns 8 to User #2 服务器将8返回给用户#2
  • User #1 asks for x value 用户#1要求x值
  • 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). 服务器向用户#1返回8( 而是要返回5 ,因为从用户#1的角度来看,这是x的最新值)。

My assumption is that I should be using something like Socket.IO (similar to the basic tutorial http://socket.io/get-started/chat/ ). 我的假设是我应该使用Socket.IO之类的东西(类似于基本教程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问题。 node.js can do sessions just fine (express-session is a very popular way to implement sessions using express and node.js). node.js可以很好地进行会话(express-session是使用express和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. 听起来您有一个DLL,一次仅支持一个用户,这实际上不适合多用户服务器使用。

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. 尽管有非常丑陋的方法可以解决此问题(例如为每个用户启动一个缓存并老化的单独的子进程,以便每个子进程都有自己的DLL的单独加载副本),但实际上,您真正需要的是一个不需要在全局内存中保留单个用户的状态,以便可以代表多个用户使用它。

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

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