I want to write a p2p program/server-client program on android/ios, how could I make the program run in the background?

The purpose of this program is

1 : Send some messages to the peers parents when their sons slide the id card.
2 : This program should be able to work in the background, in other words, when the students slide their cards, the messages should pop up on the clients(parents) side.

Thanks a lot