NiceToMytyuk
NiceToMytyuk

Reputation: 4277

How should be the system of communication between an app and a local pc?

Actually i'm going to build an app that should show to the user some requests made by one or more local pc's, the user that will use that app will be able to decline or accept that requests.

Once the request has been declined or accepted by the user the app should "notify" the local pc of the user choice.

A real example would be the following: the app will be used by chain shop or single shop administrator the seller will be able to do just some things on his shop pc and to do other stuff he will need to request the permission to the admin that will accept or decline that request.

Actually i think i will need a server as i can't communicate directly to the local pc's (i won't open the pc's ports to communicate with them directly) but how should the local pc communicate with the app throw the server?

I was thinking about something like this:

LOCAL PC => request => SERVER so now the server have to notify the app and send the request data but how (?) once the request has been accepted or declined the app will send data back to server so APP => response => SERVER and here is another hole how can i notify the local pc about the response? should i check from local pc if there is the response on the server X seconds?

Upvotes: 0

Views: 386

Answers (1)

Miku
Miku

Reputation: 597

This is quite a complex question so I'm going to give you pointers to solutions rather then solutions themselves.

It seams that you'd need to have 3 programs in total:

  1. A server
  2. PC App
  3. Android app

If you're writing it yourself I'd suggest sticking to one programming language - personally I'd recommend Kotlin since most Android apps are now being written in it, and is 100% compatible with Java.

Server should communicate using some protocol - REST is quite a good one in terms of speed and is very popular, so there should be plenty of tutorials online. Keep in mind that server should be aware that some requests should be done by user with a specific privilege, so that a hacker would not change Android app to mess around.

Both PC and Android app would communicate with the server using REST.

If you're going to write the PC App in Kotlin I'd recommend using TornadoFX as graphics library. Much better then Swing. If you want Java, then use JavaFX. Somewhere in that app there must be a thread that would be working constantly as long as the app is open (personal hint for the thread loop: while(!stopWorking)) and would ask the server if there are any new requests every X seconds. Don't bother with refresh buttons, they in my opinion are just distracting. You could even make a little "ping" noise sometimes when the app has been idle for a long time when a new request comes in so that the user can stop looking at facebook.

As for the Android app it's pretty much the same story. If you want the user to be notified when their request is ready you'd need to have a service running in the background constantly. For that you'd need to decide if you want it to start with the application, or with the phone (should the service be running after phone reboot or only after app is first started after reboot)

That is at least how I would have done it. If you really wanted to you could make it so that each PC application would also be server and when it opens and shuts down it would inform the central server that a new client is there for requests. So instead of PC app asking the main server about new requests often it can just wait until server sends it. That way both PC app and main server program would be client and server at the same time. However doing that with the Android app would be pointless. Also it's on the assumption that the PC app is not something that would be for the general public, but rather workers working in the shop.

Hope you find that helpful

Upvotes: 1

Related Questions