Search Unity

Can't connect phone to server

Discussion in 'Multiplayer' started by aje0827, Aug 15, 2018.

  1. aje0827

    aje0827

    Joined:
    Aug 10, 2018
    Posts:
    3
    I followed this tutorial to connect an android phone to a computer which is acting as the server.



    I think there is something in my wifi settings? Maybe I am using the wrong ip address or port? Anyone have any ideas?
     
  2. thedrhax14

    thedrhax14

    Joined:
    Aug 7, 2014
    Posts:
    38
    The tutorial uses not straight forward method. I would recommend to use UDP connection, because as I can see you are making external "exotic" mobile input, which is most likely will be used outside of unity3d, e.g. controlling Arduino or Rasp-Pi microprocessor using Wi-Fi.
     
    Last edited: Aug 15, 2018
    aje0827 likes this.
  3. aje0827

    aje0827

    Joined:
    Aug 10, 2018
    Posts:
    3
    Thanks so much for your feedback! I will definitely check into that. I will have the Unity running on both the phone(as the client) and the computer(as the server). I just need them to talk to each other. Would you still recommend to use UDP?
     
  4. thedrhax14

    thedrhax14

    Joined:
    Aug 7, 2014
    Posts:
    38
    If you are very sure that is supposed to work only in unity3d, then you can just check normal UNET tutorials. Otherwise, go for UDP connection.
     
  5. aje0827

    aje0827

    Joined:
    Aug 10, 2018
    Posts:
    3
    Yes I just discovered UNET ! Seems to be working much better. The only strange thing that is happening now is that I can get the app communicating between the computer and the phone only when the phone acts as the server, I can't connect. But if I try to set the computer as the server. I am pretty confused about this.

    Also might be helpful to mention that I turned the computer into a wifi hotspot for the phone to connect to. So they connect to each other directly rather than through a router. Any advice with this new approach would be greatly appreciated. Thanks again!
     
  6. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    Generally if you have trouble with a device acting as a server but you've already checked that the code works locally or another device can act as a server, the problem is probably a firewall setting. Windows software firewall for example.
     
  7. thedrhax14

    thedrhax14

    Joined:
    Aug 7, 2014
    Posts:
    38
    I don't think he made it right.
    If you are sure about UNET, make sure you use correct IP address. For example, if my phone wants to connect to computer which is a server, I need to use IP address of computer that Wi-Fi have set:

    Also, for learning and debug purposes use NetworkManager with hardcoded HUD.

    Another hint: Create your own OnlinePlayer, where you can activate different UI or set different camera based on status of server, e.g. if server is active then show the car and get ready to get data (commands) from client, else if server is not then active show UI and get ready to send commands with values of virtual joystick.

    There is actually even more things I have to mention, but I think you will figure it out and learn better on your own;)
     
    Last edited: Aug 17, 2018