-1

If I understand correctly, everytime there is a connection request, a Behavior instance is initialized. So I save some information to the extended Behavior class. However, now I want to Send a message to some connected client only (for example, behavior instance that have property productBehavior.Type == ProductType.Main).

How can I achieve this?

        foreach (var session in this.Sessions.Sessions)
        {
            // How to get the behavior instance here, so I can get the property value?
        }
Luke Vo
  • 17,859
  • 21
  • 105
  • 181

1 Answers1

0

The session is IWebSocketSession, and the Behavior also implement this interface. So the session variable in the foreach is actually the Behavior. We only need to cast it to our Behavior:

    foreach (var session in this.Sessions.Sessions)
    {
        MyBehavior b = session as MyBehavior;
        // Do anything
    }
Luke Vo
  • 17,859
  • 21
  • 105
  • 181