Search Unity

Is there a way to connect 2 mobile devices through 4G?

Discussion in 'Scripting' started by Develoop, Sep 11, 2019.

  1. Develoop

    Develoop

    Joined:
    Dec 22, 2013
    Posts:
    11
    Is there a way to connect 2 mobile devices through 4G ? 1st device would be the server and the 2nd one to be a client ? I had tried, but the connection only works over WiFi networks (public and private).

    I can't understand why the second device can't find the server (1st device) ?

    Thanks for your help :)
     
  2. palex-nx

    palex-nx

    Joined:
    Jul 23, 2018
    Posts:
    1,748
    To connect to another device you need to know its IP address. You almost surely will need nat punchtrough or relay server to connect two devices over mobile network. Otherwise it is no different from any other TCP/IP network connection.
     
    Develoop likes this.
  3. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    You'd typically need a public server which both devices can talk to. This server would either just facilitate the connection (nat punchthrough), or relay all data to the other connected devices. Both @palex-nx already mentioned.

    4G wireless providers don't necessarily allow connected devices to function as a traditional server, or even provide routable IP addresses, so don't bank on that being the case.
     
    Develoop and lordofduct like this.
  4. Develoop

    Develoop

    Joined:
    Dec 22, 2013
    Posts:
    11
    Thank you very much for your answers and for your help.
    For sure I will need a server (VPS or Dedicated) to record the IPs and to know when somebody is online or offline.
    But my question is when I know the both IPs - server IP (created from smartphone) and client (another phone) why I can't establish a connection between them, I don't want to send the data through my third party server?
    I want to make a communication between 2 mobile devices over 4G. Have you made that ?
     
  5. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    Again....
    It is not uncommon for wireless carriers to block client connections to servers hosted on wireless devices (wireless provider firewall configuration), or to only hand out IP addresses which are non-routable (such as a 10.x.x.x address - basically any NAT address).

    Edit:
    For example, I just checked the IP address of my phone assigned by AT&T, and it just happens to be a 10.x.x.x address. Since addresses in that range simply don't exist on the Internet (they are private addresses https://en.wikipedia.org/wiki/Private_network#Private_IPv4_addresses which any packet directed to one received by an Internet router will simply drop instead of forward on), a client on its own cannot just send a request to my phone. Research how NAT works for more information.
     
    Last edited: Sep 11, 2019
    Develoop likes this.