Send event from server to client #1917
-
Hi NVFlare community, I would like to send an event from server to all FL clients when a new RUN starts. I'm using the NVFlare docs (https://nvflare.readthedocs.io/en/main/programming_guide/event_system.html) to do this, however, the event is fired on the server side but never reaches the client side. Any idea what I am doing wrong? Is there another alternative to events? or are they the best option for sending data between client and server? My intention is to send data (basic python types, e.g. string or ints) to initialize an object on client side based on the type of task the server wants to execute. Server class Server(FLComponent):
def __init__(self) -> None:
super().__init__()
def handle_event(self, event_type: str, fl_ctx: FLContext) -> None:
if event_type == EventType.START_RUN:
engine = fl_ctx.get_engine()
fl_ctx.set_prop(key="yourEventDataKey", value="yourEventData", private=True, sticky=True)
engine.fire_event(event_type="custom_event", fl_ctx=fl_ctx) Client class Client(Learner):
# init, and other functions goes here
def handle_event(self, event_type: str, fl_ctx: FLContext):
if event_type == "custom_event":
# Do something :) Thank you. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
There are probably multiple-ways to achieve the goal, not necessary via the sever to client event.
hope this helps |
Beta Was this translation helpful? Give feedback.
-
On the server, instead of using engine.fire_event(), change to use engine.fire_fed_event(), then this will fire the event to the client side. |
Beta Was this translation helpful? Give feedback.
There are probably multiple-ways to achieve the goal, not necessary via the sever to client event.
define a workflow, you can write controller to define a workflow to do the task you like to do. You can send or broadcast the task to client(s), client receive and handle the tasks. This new workflow can be added to before or after the existing workflows
If above doesn't fit your needs, you can leverage use send Aux message ( 2.3.x or before), which directly send the target audiences (client or server). split learning example used this approach. Aux channel API will be hidden to use after 2.4.x as 2.4.0 will provide more higher level abstraction to achieve the same goal
what about usin…