Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

I am so LOST! Android client to Pc master server

Discussion in 'Multiplayer' started by Leuki, Mar 14, 2018.

  1. Leuki

    Leuki

    Joined:
    Feb 27, 2014
    Posts:
    130
    Ok, bare with me.. I am using Barebones Networking Package and its pretty straight forward.. Theres a master server and a client connection. Master server is downloaded and running on my pc as .exe.. It is using host 127.0.0.1 and port 5000.. Default stuff i know.. So, all that does is start the server from that host addr and port that is on my computer. I have allowed port forwarding on the port. I have also allowed incoming and outgoing connections in firewall.. I then connect the app with client connection that connects to that master server on my computer with an android phone that after succesful login or reg, will then open a chat window.. However i cannot get past connecting.. It doesnt connect. Do i need to specify a connect on my ip and not the host server 127.0.0.1? I can easily run the client connection and chat through a windows exe app.. Server runs and client runs and i can have two different clients connected and chatting.. But i just cant get it to work aver a mobile app.
     
  2. arcturgray

    arcturgray

    Joined:
    Nov 20, 2016
    Posts:
    12
    127.0.0.1 means "that very computer that the program is running on". So when you try to connect from your mobile app to 127.0.0.1, it tries to connect to itself. It works when both client and server are on the same computer, because they are, well, on the same computer.

    Open command prompt and enter ipconfig. There you will see IP Address. Try using it from mobile.

    And if server is bound to 127.0.0.1, it would monitor connection requests coming from the same computer, but not from the "outside". For it to monitor all connection requests it has to be bound to all available interfaces. I don't know how it can be indicated in MSF. Maybe empty string or something. Or maybe MSF creator decided to use 127.0.0.1 string for that purpose in case of master server.
     
    Last edited: Mar 14, 2018
  3. Leuki

    Leuki

    Joined:
    Feb 27, 2014
    Posts:
    130
    Well you can input any server address. I used 127.0.0.1, my IPv4, my ISP Adress. All connect. But, i think the reason the android wont connect to my pc master server is because i need to set port forwarding within the router.
     
  4. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    If you're trying to connect from another network, such as your mobile data plan, then yes you would need to use port forwarding on your router. You could connect your mobile device to your wifi behind your router though to eliminate router settings from the equation.
     
  5. Leuki

    Leuki

    Joined:
    Feb 27, 2014
    Posts:
    130
    yes, but when making my chat system within my app im making, that wouldnt be reasonable. I need that master server to host connection to all clients.
     
  6. Leuki

    Leuki

    Joined:
    Feb 27, 2014
    Posts:
    130
    Client sends a message, router allows incoming message to server, then allows outgoing connection to all clients on that master server.
     
  7. Leuki

    Leuki

    Joined:
    Feb 27, 2014
    Posts:
    130
    Ive already added incoming and outgoing connections on my port i specified, as well as defined it as a TCP. And allowed those same incoming and outgoing rules to the master server application as well. So im assuming its lands on the router which i will test when i get home tomorrow. Will update this post tomorrow.
     
  8. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    I was referring to just troubleshooting your problem, not your final configuration as you plan to deliver your game. Your issue could be caused by incorrect addresses, software firewall settings, or other issues. Adding your router settings on top of that will only make troubleshooting take longer.

    Connecting your mobile device to your local wifi and connecting to your computer's IP address instead of your router's address, eliminates the router as the source of any problem. If you still have an issue, you know to stop messing with your router settings for now and look at settings on your computer or on your mobile device. If it works, you know to stop messing with your software settings because the issue is likely with your router or somewhere outside of your local network. Its a test that takes 3 minutes and eliminates potentially hours of troubleshooting.

    Basically here is how you should step through any network connection issue, and should always pinpoint the source of the problem in a matter of minutes

    1) Connect from build to editor or build to build on the local computer using 127.0.0.1
    2) Repeat step 1 but use your actual IP address of your network interface
    3) Use another computer on your local network to run a build to connect to your IP address of the first computer
    4) If your game is designed to be delivered to another platform, such as mobile, now you connect a mobile device to your local network and connect to the computer's IP address
    5) If all above work just fine, now you have a computer or other device outside of your network attempt to connect to your router's IP address, which should be port forwarding to the IP address of your computer hosting the game. This is a complete waste of time though if you have issues with any step from 1 to 4.
     
    Last edited: Mar 14, 2018
  9. Leuki

    Leuki

    Joined:
    Feb 27, 2014
    Posts:
    130
    Well the problem stems from that in itself. I can ONLY connect to my master server that is running on my PC through the wifi connection. If i disconnect my wifi from my mobile device, then i lose connection. I then try reconnecting using only my android device 4g lte network, and it doesnt connect.
     
  10. Leuki

    Leuki

    Joined:
    Feb 27, 2014
    Posts:
    130
    I attached two images.. One being the Master server running on port 5000 and IP ********* < my IPv4 address. AS well as the client to show it connects to the IPv4. It doesnt show on the master itself cause it calls it from script. but the client shows it as well as what port.. And the other shows two clients in chat as well as the sign in showing connections.
     

    Attached Files:

  11. Leuki

    Leuki

    Joined:
    Feb 27, 2014
    Posts:
    130
    Steps 1-4 all work. I can connect to my pc from another pc, i can connect to my pc using wifi on my android.. I have used 127 as well as my isp.. The second i take my android off of wifi, i am no longer connected. So i cannot connect using only my 4g network.. which is telling me that anyone not on the same wifi as me wont be able to connect.
     
  12. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    So the problem is likely with your router configuration. Make sure your client is connecting to the public IP address of your router, not its internal address. Make sure the router has the correct UDP port forwarded to your computer's IP address (my understanding of barebones networking API is it is just a layer on top of UNET LLAPI, which uses UDP by default, though can be configured for websockets, but I'd assume barebones also just uses UDP by default).