Closed endertable closed 2 months ago
remote_address gives you the IP address & port.
In general, I would recommend that you give connections unique ID. Perhaps you can leverage connection.id?
If you need to share the ID between the client and the server, then there's many way to do it. For example, clients could connect to ws://<your-server>/<a-unique-id>
, then the server would extract the unique id from connection.request.path
and use it as the key for identifying clients. You can also send an initial message on the connection to exchange an ID, one way or the other. (NB: I don't have details of your architecture and use case; I don't know your constraints; maybe that doesn't make sense.)
I had been using an 'initt' initial message so I just added the differentiating element as an ID instead of using the IP. Worked like a charm. Minimal revisions to some things and DONE.
Thanks for your help and rapid response. :)
Hello. OK, this is not really an issue, it's more of a brain fart that I am having. So I have this WSS server up for over a year now and it is working great but now I need to make it where the local host runs a few scripts on it as well. The problem is sometimes multiple scripts will start at the same time and because they both have client IP of 127.0.0.1 the script that runs first will usually receive the answer for both scripts. These scripts send queries to different cameras and need their own distinct responses.
Is there a way I can have the server distinguish between the two requests other than using the IP address? I have been using the IP of the clients as the user_id and has worked great as they have always been different, but now that these local scripts all have an IP of 127.0.0.1 there could be a race issue. I know I can delay the running of concurrent scripts, and if I have to I will, but hoping not.
Is IP the only way to distinguish the different clients or can it also use a remote port or something else?
Am using something like the following in my server (user_id is the IP of client):
await connected_clients[user_id].send(message)
Thanks for any help and for the great software..