Author Topic: Server setup  (Read 4345 times)

Hoskins355

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 4
    • View Profile
Server setup
« on: July 15, 2014, 04:57:25 PM »
I am trying to create a multiplayer wifi mobile game for android and ios. What are the different options I have for the server. Can the mobile app run the server? Do I need an online server like Amazon EC2? Or could I just run it on my website? Do you have any documentation on server setup?

Thanks
Brandon

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Server setup
« Reply #1 on: July 16, 2014, 12:28:33 AM »
You can run a server on a mobile device, but you won't be able to reach it via 3G. It will only be reachable via WiFi. To start a server from within your game, just call TNServerInstance.Start.

Hoskins355

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 4
    • View Profile
Re: Server setup
« Reply #2 on: July 16, 2014, 10:18:32 AM »
That didn't explain the differences between server setups. So if the player host the game is it only available on local network or can he play anyone? Any documentation on server setup? I have been trying for 2 days to set this up. I have found no good documentation on how to set this up. I have never set up a multiplayer game before so I need a step by step guide to get up and running.


Thanks
Brandon

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Server setup
« Reply #3 on: July 17, 2014, 03:03:15 AM »
It's the same as any other multiplayer game. If you start a server, you basically make it possible for others to join -- however unless you give them your address, they won't be able to find you. You can make your server discoverable by the network if you wish, or you can register with a remote lobby server. Your original question was about what options you have for the server. There is only one option -- you start it, and there you go. The only options you have is for its discovery. No discovery (by doing nothing), LAN discovery (using TNUdpLobbyClient), or WAN discovery by registering with a remote lobby server that's hosted somewhere accessible (basically 3rd party).

ExampleMenu.cs script that comes with TNet handles all this for you. For example, this is the code that starts the server:
  1.                                         int udpPort = Random.Range(10000, 40000);
  2.                                         TNLobbyClient lobby = GetComponent<TNLobbyClient>();
  3.  
  4.                                         if (lobby == null)
  5.                                         {
  6.                                                 TNServerInstance.Start(serverTcpPort, udpPort, "server.dat");
  7.                                         }
  8.                                         else
  9.                                         {
  10.                                                 TNServerInstance.Type type = (lobby is TNUdpLobbyClient) ?
  11.                                                         TNServerInstance.Type.Udp : TNServerInstance.Type.Tcp;
  12.                                                 TNServerInstance.Start(serverTcpPort, udpPort, lobby.remotePort, "server.dat", type);
  13.                                         }
So depending on which Lobby Client you have attached, it will either have no discovery at all (lobby is null), UDP discovery (LAN) or TCP discovery (WAN, remote server).

Deozaan

  • Newbie
  • *
  • Thank You
  • -Given: 44
  • -Receive: 4
  • Posts: 42
    • View Profile
    • Deozaan.com
Re: Server setup
« Reply #4 on: July 22, 2014, 08:31:51 AM »
You can run a server on a mobile device, but you won't be able to reach it via 3G. It will only be reachable via WiFi. To start a server from within your game, just call TNServerInstance.Start.

The only options you have is for its discovery. No discovery (by doing nothing), LAN discovery (using TNUdpLobbyClient), or WAN discovery by registering with a remote lobby server that's hosted somewhere accessible (basically 3rd party).

Are you saying that starting a server on mobile will not allow others on 3G/4G to access it even if they know your IP address or you have a lobby server that is hosted somewhere accessible?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Server setup
« Reply #5 on: July 22, 2014, 07:58:30 PM »
Inbound connections are not possible via 3G. You can connect to a remote server using a 3G connection, but you won't be able to host a server yourself.

Deozaan

  • Newbie
  • *
  • Thank You
  • -Given: 44
  • -Receive: 4
  • Posts: 42
    • View Profile
    • Deozaan.com
Re: Server setup
« Reply #6 on: July 26, 2014, 02:34:28 PM »
Is there any way for me as a developer to know if players are connected via WiFi or 3G/data? So I can enable or disable the option to host depending on their connection type?

Or do I just need to show a warning on mobile platforms informing them that 3G/data servers/hosts can't have any incoming connections?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Server setup
« Reply #7 on: July 27, 2014, 03:32:44 AM »
You can query this from Unity via Application.internetReachability. By default I don't allow outbound traffic via 3G in Starlink. The players have to manually enable this in game's options.