Search Unity

Communicating between PC app and Android App

Discussion in 'Multiplayer' started by invisage, Jan 8, 2021.

  1. invisage

    invisage

    Joined:
    Jun 27, 2019
    Posts:
    23
    Have a pc 'management' app and a table 'display order' app. Not too much information is going to be passed on a daily basis, just a dozen or so orders with 3-5 fields of information.
    Ideally, I want this to run over wifi so its not dependent on the internet being available, so no cloud options. Very familiar with Unity but never done any networking, but have done API communication with JSon.

    So could I use something like photon/firebase to do the above? Another option thats been suggested is to setup a local database on the pc and have the tablet apps query that?

    Any feedback or thoughts on the avenue I should take would be appreciated :)
     
    BetaMark likes this.
  2. BetaMark

    BetaMark

    Joined:
    Sep 27, 2014
    Posts:
    229
    Over the last few years, Unity has *really* be maturing their UI toolkits, and with more enterprise focus (like they have done with the architecture and construction space), I expect to see more and more UI apps like this being built just like this, so I wanted to start by saying you are not alone in asking about this stuff.

    Now, on to some answers specifically for your case.

    Unity does have its own UnityWebRequest class which you can use to talk GET and POST directly to a web server which can be on the internet or just on your local Wifi LAN. They would work just like it would as if you had built a web app in React/Angular/VueJS -- but instead you built it in Unity with c#.

    To make things easier on you, there are two assets which add to the abilities of UnityWebRequest which I have personally tested for my projects. Best Http/2 (on sale right now at 50% off) and Web Api Kit: Core. Those two help you handle a lot of the network things like authentication and seamlessly converting from a C# data structure to json, and then back again from the json response into a c# data structure to use in your app. Both would "just work" over the wifi and the internet, as long as your app knows the ip address of your server.

    You only really need to look into Photon, Firebase, MLAPI or Mirror until you need to do a lot of tiny updates very frequently such as updating the X and Y position of a window to the server so that everyone else connected to the server can see you move the window in real time.

    Hope that helps!
     
    invisage likes this.
  3. invisage

    invisage

    Joined:
    Jun 27, 2019
    Posts:
    23
    Thanks for the reply.

    Im pretty comfortable with JSON having done Paypal and AWS integration.

    I see where you are going with the UnityWebRequests but very unfamiliar with setting up local web servers. Do I need to set up one outside of Unity for the PC and Tablet apps to communicate through or can something like Best Http/2 do that? Im all for learning something new and reading documentation but didn't even know where to start on this one lol
     
    BetaMark likes this.
  4. BetaMark

    BetaMark

    Joined:
    Sep 27, 2014
    Posts:
    229
    In my suggestion, the "server" for your application would run on its own machine (or docker container if you want to develop it locally) -- and you would talk to it from your Unity app with either UnityWebRequests or Best Http/2 requests to that app.

    My suggestion is really only useful if you are already familiar with building those kinds of servers and REST APIs though. I read that you had "done API communication with JSon" in your original question and assumed you had setup the API and were talking REST/JSON to and from the API.

    There are a bunch of great youtube videos about RESTful APIs with Unity -- take a look at any of them and let me know if you have specific questions about how it would all work in your particular situation.
     
    invisage likes this.
  5. invisage

    invisage

    Joined:
    Jun 27, 2019
    Posts:
    23
    Have used PayPal and AWS API's. So have communicated with existing setups, but not setup my own. So if I have a PC at the business I need to setup my own API on that machine (as a docker container). Then can use webrequests between the pads and the pc for the information they need?

    Will have a look this weekend for some info on setting up an API then :)
     
  6. aocardy

    aocardy

    Joined:
    Aug 18, 2021
    Posts:
    5
    The Ajax security system connects to a mobile device via Wi-Fi to detect movement. When something happens, the data is sent to the device as a notification. I would recommend using a an ajax app to monitor cameras with your mobile device. You can use any application that allows you to view and record data about your movement. Some applications also allow you to use Android devices (for example, Smart Home).