Giter Site home page Giter Site logo

How to get client instance id about iodine HOT 3 CLOSED

rschwass avatar rschwass commented on May 27, 2024
How to get client instance id

from iodine.

Comments (3)

rschwass avatar rschwass commented on May 27, 2024

def initialize(channel, controller = 0)

so when i init the client, i specify controller=1 , how do i think store that clients "ID" that I can parse when each client closes?

from iodine.

boazsegev avatar boazsegev commented on May 27, 2024

@rschwass , thank you for opening this issue and for your interest in iodine.

Since the HTTP request's env Hash object is accessible through client.env, it should be quite easy to produce a UUID and assign it to the connection. It should be quite easy to store this connection's UUID as well as the originating processes' ID in a database of some sorts...

However, for most use cases, this approach would create scalability issues.

For example, assuming you want to create an "online" indicator for a user: How do the connection indicators link to a specific user? What would happen if a user comes online on two different browsers, or on a browser + app? Does each connection get a different uuid? What if two different machines handle these connections? What if a server crashes or goes offline before calling the connection's on_closed callback?

Much better to handle this as a user related event, using the user's ID rather than the connection ID, separating the online/offline responsibility from the connection object.

i.e., publish an {event: "connected", user: "[email protected]", at: Time.now} or an event {event: "disconnected", user: "[email protected]", at: Time.now}. Let the event handler (which might be a different micro-service) increase or decrease a user associated online counter. Perhaps add a last-seen indicator, or a timer, or listen to some user produced events (such as ack events), so the online count is reset if a client doesn't answer a ping or appears inactive for too long (having a browser open doesn't mean the person is still there)...

Suddenly, instead of handling connections, you focus on the user itself - a much more relevant entity.

I hope this helps. I wish you the best of luck.

from iodine.

rschwass avatar rschwass commented on May 27, 2024

Thank you. My clients are not users but machines. I ended up going with the client.env method.

from iodine.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.