Android Question Detecting another device in a network and do some transmissions between the devices


Howdy. I am planning to make a server-client system for my 2 phones. Phone A should act as a "server" and Phone B as a client. Both devices are in the same network (Phone A acts as the hotspot btw). The purpose is very niche, Phone A has a broken screen and is connected to a PC with scrcpy in order to see the display, and i want to get some data like current battery, sms, and notifications there to my another device for convinience. I tried an SMS-based option, but it will not be very good for long term use.

What i intend to do is that Phone B can fetch some data to Phone A. However, I do not know where to start exactly with how to make Phone B detect Phone A, connect them, and do transmissions.