That answers your questions (2) and (3): check the source address of the 'message' (what format is the message? UDP packet? How are you reading the message?) to identify what network the message came from, and you target a network by way of the IP address you're sending to.
The Linux device should receive messages from Group A (through router A), process the information and send notification of the result to Group B (through router B) and vice versa. I want the Linux device to connect to both router A and router B and act as an intermediary between the two groups. Group A devices are connected to WiFi router A and group B devices to WiFi router B (It is necessary that they should not be connected to the same router).
My requirement: I have two sets of devices (Group A and group B) that need to communicate with each other but not directly. I want to connect to two networks simultaneously using the Ethernet and in-built WiFi or to two WiFi networks by installing an additional WiFi adapter.