对每个用户强制单个Web套接字连接是否有任何不利之处? [英] Is there any disadvantage in enforcing a Single Web Socket Connection per User?

查看:64
本文介绍了对每个用户强制单个Web套接字连接是否有任何不利之处?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了

为每个用户强制一个Web套接字连接

Enforcing a Single Web Socket Connection per User

它指出一些优点是它使服务器端逻辑在其他方面不那么复杂.我的问题是

It states that some of the advantages are that it makes the server side logic less complex among others. My questions are

  1. 这样做有什么不利之处吗?
  2. 使用websocket创建实时应用程序时,这是一种常见的/良好的做法吗?

----------- EDIT -------------

  1. 做了一些与socket.io 共享快速会话.这使我想到了这个问题:是否有
  1. After doing some research I have learnt that you can share express sessions with socket.io. Which brings me to this question: Is there any need/advantage of Enforcing a Single Web Socket Connection per User if socket.io and express are sharing sessions? Or is it fine to allow a user to have multiple socket connections as long as they are all linked to their user._id or something that identifies them?

推荐答案

对于这个问题,确实没有通用的答案.只有在您的特定应用程序,它的功能,它的设计目标,允许多个连接的特定结果(肯定和否定)的上下文中的答案,它的扩展目标(涉及群集),通过允许或不这样做会导致什么UI复杂性禁止多个连接,通过允许或禁止多个连接等,服务器端的复杂性等等.

There really is no generic answer to this question. There are only answers in the context of your specific application, its features, its design goals, the specific consequences (both positive and negative) for allowing multiple connections, its scale goals (is clustering involved), what UI complications there are by allowing or disallowing multiple connections, what server-side complications there are by allowing or disallowing multiple connections, etc...

这里没有通用答案.

为每个用户强制一个Web套接字连接

Enforcing a Single Web Socket Connection per User

本文首先介绍了具有特定设计目标的特定应用程序(游戏),以防止用户一次通过多个页面访问服务器,因为这样做可能会给玩家带来不公平的优势..这是为每个用户强制单个webSocket连接的正当理由.该文章中没有任何地方表明这样做是出于其他原因.

First off, this article describes a specific application (a game) that has a specific design goal to prevent a user from accessing the server through more than one page at a time because the player could perhaps create an unfair advantage in doing so. That's a valid reason for enforcing a single webSocket connection per user. Nowhere in that article is it indicated that this is done for any other reason than that.

对每个用户强制执行单个Web套接字连接是否有不利之处?

Is there any disadvantage in enforcing a Single Web Socket Connection per User?

这实际上取决于您的应用程序,服务器实现和设计目标.将用户限制为一个正常运行的webSocket意味着他们一次只能打开一个活动的选项卡,窗口或设备.对于一些应用程序,这是理想的选择.对于其他人来说,它只是在限制用户,而对应用程序或用户没有好处.

It really depends upon your application, your server implementation and your design goals. Limiting a user to one functioning webSocket means that they can only have one active tab, window or device open at a time. For a few applications, this is a desired thing. For others, it just over constrains the user with no benefit to the app or user.

实施此限制时,您必须弄清楚在各种情况下将要执行的操作以及如何确保用户仍然具有适当的(和良好的)用户体验.例如,假设我在桌面上打开了一个浏览器窗口(并且没有关闭它),那么我走出前门并想在手机上打开相同的站点.如果电话的Web浏览器由于在另一台计算机上已经为该用户打开了webSocket而被拒绝访问该网站或被拒绝提供适当的功能,则这将导致沮丧的用户突然无法使用该应用程序.像这样的其他许多边缘案例,都必须经过仔细考虑和适当设计.

When you implement this limitation, you have to figure out what you're going to do for a whole bunch of circumstances and how you make sure the user still has an appropriate (and good) user experience. For example, supposed I have a browser window open in my desktop and (without closing it), I walk out the front door and want to open the same site on my phone. If the phone's web browser is denied access to the site or denied proper functionality because there's already a webSocket open for that user on a different computer, then that leads to a frustrated user who suddenly can't use the app. There are numerous other edge cases like this that all have to be carefully thought out and designed appropriately.

因此,我认为在大多数情况下,如果只让用户打开的每个窗口都拥有自己的webSocket,那么它会产生少得多的用户体验边缘情况.您可以让应用程序在不活动后超时,以最终清理不活动的套接字,并确保将来用户返回该页面时在不活动页面中具有清晰的用户界面.

So, I'd argue that in most cases, it creates far less user-experience edge cases if you just let each window the user opens have it's own webSocket. You can have the app time things out after inactivity in order to eventually clean up sockets that are inactive and make sure that has a clear user interface in the inactive page if a user returns to that page in the future.

因此,为每个用户强制单个webSocket连接的一个明显的缺点是,您有很多用例来考虑它对用户的确切工作方式,并且用户总是清楚正在发生的事情并且他们是否能够始终按照自己的意图进行操作,尤其是在更换设备或意外打开该应用的第二个窗口时.

So, a clear disadvantage of enforcing a single webSocket connection per user is that you have lots of use cases to think through how exactly it works for the user and is the user always clear what's happening and can they always do what they intend, particularly when changing devices or accidentally opening a second window for the app.

这使得服务器端逻辑在其他方面不那么复杂

it makes the server side logic less complex among others

嗯,这实际上取决于应用程序的设计.如果webSocket只是在与自己的网页进行交互,那么让每个网页都拥有自己的webSocket根本就没有额外的麻烦.另一方面,如果webSocket的目的是使该用户的所有打开的屏幕保持最新状态,并且信息相同,那么您的服务器不仅需要将发往某个特定用户的信息发送到一个webSocket,但针对该用户的每个webSocket.由于大多数应用程序已经具有某种查找属于给定用户的webSocket的机制,因此,这意味着它不仅发送消息给一个webSocket,而且还发送给属于该用户的所有webSocket.通常可以将此逻辑隐藏在每个人都可以调用的函数的后面.在socket.io(位于webSocket之上的一层)中,可以使用room概念来跟踪属于给定用户的所有套接字.

Well, this really depends upon the app design. If a webSocket is just interacting with its own web page, then allowing each web page to have its own webSocket is no extra complication at all. If, on the other hand, the purpose of the webSocket is to keep all open screens for that user up-to-date with the same information, then your server needs to not just send info destined for one particular user to only one webSocket, but to each webSocket for that user. Since, most apps already have some sort of mechanism for finding a webSocket that belongs to a given user, this just means that instead of only sending a message to one webSocket, it sends to all the webSockets that belong to that user. This logic can usually just be hidden behind a function that everyone can call. In socket.io (a layer on top of webSockets), one can use the rooms concept to keep track of all the sockets that belong to a given user.

使用websocket创建实时应用程序时,这样做是一种常见/好的做法吗?

Is it a common/good practice to do so when creating real-time applications using websockets?

这并不是我使用具有服务器推送功能的应用程序的经验(例如,像stackoverflow),尽管应用程序是否正在使用webSocket或其他某种机制来获取更新信息并不总是很明显.用户界面.如果您尝试在服务器上打开第二个窗口,您多久会收到某种类型,错误或消息?这很少发生在我身上.

That's not been my experience in using applications that have some server-push aspect to them (like stackoverflow, for example), though it isn't always obvious whether an app is using a webSocket or some other mechanism for getting updates to the UI. How often do you get some type or error or message if you try to open a second window on a server? That rarely happens to me.

如果socket.io和express正在共享会话,是否需要/有利于每个用户执行单个Web套接字连接?

Is there any need/advantage of Enforcing a Single Web Socket Connection per User if socket.io and express are sharing sessions?

否,无需强制执行.如果这是您的设计目标,则通过任何形式的用户登录,您都可以轻松地在属于该用户的所有连接之间共享用户会话.请记住,是否始终要由同一用户进行所有连接的同一会话是特定于应用程序的.这实际上取决于应用程序的需求以及您在会话中的工作.

No, there is no need to enforce it. With any sort of user login, you can easily share user sessions among all connections belonging to that user if that's your design goal. Keep in mind that it's application specific whether you always want the same session for all connections by the same user. It really depends upon the needs of the application and what you are doing with the session.

还是允许用户具有多个套接字连接(只要它们都链接到其user._id或标识它们的东西)就可以了?

Or is it fine to allow a user to have multiple socket connections as long as they are all linked to their user._id or something that identifies them?

同样,这是特定于应用程序的.在大多数情况下,我知道这很好,并且将用户限制为仅一个选项卡/窗口将被许多用户视为不必要的设计限制.

Again, this is application-specific. In most cases, I know of it's fine and limiting the user to only a single tab/window will just be seen as an unnecessary design limitation by many users.

这篇关于对每个用户强制单个Web套接字连接是否有任何不利之处?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆