Skip to content

Get client (socket) info from an event #1889

@srdjus

Description

@srdjus

Hello,
I'm using asyncua==1.1.0 and trying to build an OPC UA server that performs monitoring. Specifically, I’d like to know when a client connects and when it reads or subscribes to data items. For this test, I'm running a server without authentication. The information I collect needs to be sent to a remote location.

I attempted to handle the following server callbacks:

self.server.subscribe_server_callback(
    CallbackType.ItemSubscriptionCreated, self.create_monitored_items
)
self.server.subscribe_server_callback(
    CallbackType.ItemSubscriptionModified, self.modify_monitored_items
)
self.server.subscribe_server_callback(
    CallbackType.ItemSubscriptionDeleted, self.delete_monitored_items
)
self.server.subscribe_server_callback(
    CallbackType.PostRead, self.read_monitored_items
)

Inside these callbacks, I tried to identify which client triggered the event:

def modify_monitored_items(self, event, dispatcher):
    # TODO: Somehow get client info
    print(f"Modify monitored items by client: {client_info}")

I can list connected clients through the BinaryServer connections, but I don’t see how to associate a specific client with a specific event (like a read or monitored item creation).

I’m not sure if I’m taking a completely wrong approach, but I started exploring this direction and would like to hear about possible alternatives. In short, my main questions are:

  • Is there an existing way to retrieve client info (session, endpoint, or socket) inside these server callbacks?
  • Also, is it possible to get socket information (like IP/port) when a client connects, even before any read or subscription occurs?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions