使用node.js从POST请求中唯一标识用户 [英] Uniquely identifying a user from a POST request with node.js
问题描述
I'm making a browser game that utilizes voice communication, to record audio in the browser I'm using wami-recorder which uses flash to send a POST request to the server with the recorded audio, only it doesn't seem to give me any control over the request.
我的游戏服务器(用node.js/express编写)需要能够从接收到的音频中识别客户端,并将其与来自socket.io的正确Web套接字配对
My game server, which is written in node.js/express, needs to be able to identify the client from the audio it's received, as well as pair it with the correct web socket from socket.io
我已经考虑过使用ip地址,但是如果有多个具有相同地址的客户端将不起作用.我还考虑过为客户端分配一个唯一的URL(这是wami让我做的唯一事情之一),以便他们将音频发送到客户端,除非我不想以某种方式窃取该url,而其他人则有能力向其发送音频
I've considered using the ip address, however it wouldn't work if there were multiple clients with the same address. I've also considered assigning a unique URL to the client (one of the only things wami let's me do) for them to send the audio to, except I wouldn't want that url stolen somehow and for someone else to have the ability to send audio to it
所以我想知道express.js中的发帖请求是否可以一致地标识客户端.
So I'm wondering if there's a way a post request in express.js can consistently identify a client.
推荐答案
您通常的选择是:
- 在每个发帖请求中包含可识别用户的数据
- 要让用户登录"并设置一个标识该用户的cookie,该cookie应该随发布请求一起自动发送,这样您就可以检查cookie服务器端以查看正在发送的用户.
如果您在评论中说,如果您不能影响与请求一起发送的数据,那么您将需要设置一个cookie,以在发送请求之前识别用户,浏览器将自动包含带有请求的cookie,然后您的服务器端代码可以检查请求附带的cookie,以查看它是哪个用户.这是一种通常的方式,人们可以登录"网站,然后服务器跟踪给定请求来自哪个用户.
If, as you say in your comments, you can't influence the data that is sent with the request, then you would want to set a cookie that identifies the user before the request is sent and the browser will automatically include the cookie with the request and then your server-side code can examine the cookie that comes with the request to see which user it is. This is the usual way that one "logs in" to a web-site and the server then keeps track of which user a given request is from.
这篇关于使用node.js从POST请求中唯一标识用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!