简体   繁体   English

如何使用socket.io设置和读取cookie?

[英]How do I set and read a cookie using socket.io?

I'm using socket.io in my node.js app and I'm trying to set a simple cookie and read back the value of the cookie later. 我在我的node.js应用程序中使用socket.io,并且试图设置一个简单的cookie并在以后读取该cookie的值。 How do I do that with socket.io? 我该如何使用socket.io? Does it support this natively or do I need to write client-side functions for manipulating cookies and then create socket.io events to use them? 它本身是否支持此功能?我是否需要编写用于处理Cookie的客户端函数,然后创建socket.io事件以使用它们?

socket.io can use different transport mechanisms ( http://socket.io/#browser-support ), eg flash raw sockets. socket.io可以使用不同的传输机制( http://socket.io/#browser-support ),例如flash原始套接字。 They're not related to common HTTP connection at all, hence it's better to set cookie manually at client-side. 它们根本与普通的HTTP连接无关,因此最好在客户端手动设置cookie。

Setting cookies won't affect that flash connection at all, though. 不过,设置cookie根本不会影响该Flash连接。 You may need to manually not only generate some token, but also bypass it as connection parameter. 您可能不仅需要手动生成一些令牌,还需要绕过它作为连接参数。

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

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