Author Topic: "Start Local Server" custom IP  (Read 9861 times)

GantZ_Yaka

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 21
    • View Profile
"Start Local Server" custom IP
« on: January 30, 2014, 05:12:17 AM »
Hello! I tried your demo on diffferent PC and got a different results. On some computers/notebooks when I push button "start local server" - the server is assigned a wrong address, such as 127.0.0.1 or other - and other clients on another PCs cant connect to this server. tell me, where does the server address when this button is pressed, and how can I  set it manually from the script?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: "Start Local Server" custom IP
« Reply #1 on: January 30, 2014, 05:03:40 PM »
127.0.0.1 just means your local computer. It's a loopback address. When you start a server, 127.0.0.1 just means "this computer". On other computers you actually need to use the server's address instead in order to connect.

The Menu example that comes with TNet lets you see the list of other servers hosted on the local area network, but if connecting directly you have to use the proper IP address.

GantZ_Yaka

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 21
    • View Profile
Re: "Start Local Server" custom IP
« Reply #2 on: January 31, 2014, 04:23:18 AM »
Sometimes  loopback address itself turns something like 192.168.134.1 (while his real local address on the network is quite different, for example 192.168.1.34)

Help me pls sample code, how do I get the program to automatically take the correct local IP of the computer on which the program is running - and send it to the lobby-list of servers to be able to join him on the other clients without resorting to manual input IP addresses. I need everything to be automatic, and the players did not need to drive hands - just pushing the buttons: make game, join game, etc. is it real?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: "Start Local Server" custom IP
« Reply #3 on: January 31, 2014, 12:50:53 PM »
TNet automatically sends the internal and external IPs to the lobby server. External IP can sometimes not be detected as it's done by accessing a remote website, which is public and used by everyone, and as such may not always respond. I've posted the PHP script for it in the past -- it's a good idea to put it up on your own web server so it's more reliable.

http://www.tasharen.com/forum/index.php?topic=7081.msg33577#msg33577

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: "Start Local Server" custom IP
« Reply #4 on: January 31, 2014, 01:14:16 PM »
Also, as a note you can try changing TNet.Tools.localAddress from this:
  1.                                         IPHostEntry ent = Dns.GetHostEntry(Dns.GetHostName());
  2.  
  3.                                         foreach (IPAddress ip in ent.AddressList)
  4.                                         {
  5.                                                 if (IsValidAddress(ip))
  6.                                                 {
  7.                                                         mLocalAddress = ip;
  8.                                                         break;
  9.                                                 }
  10.                                         }
to this:
  1.                                         IPAddress[] ips = Dns.GetHostAddresses(Dns.GetHostName());
  2.  
  3.                                         for (int i = 0; i < ips.Length; ++i)
  4.                                         {
  5.                                                 if (IsValidAddress(ips[i]))
  6.                                                 {
  7.                                                         mLocalAddress = ips[i];
  8.                                                         break;
  9.                                                 }
  10.                                         }

GantZ_Yaka

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 21
    • View Profile
Re: "Start Local Server" custom IP
« Reply #5 on: February 03, 2014, 03:24:08 AM »
TNet automatically sends the internal and external IPs to the lobby server. External IP can sometimes not be detected as it's done by accessing a remote website, which is public and used by everyone, and as such may not always respond. I've posted the PHP script for it in the past -- it's a good idea to put it up on your own web server so it's more reliable.

http://www.tasharen.com/forum/index.php?topic=7081.msg33577#msg33577
Help me pls,  how to use your  PHP script in Unity?
  1. <?php
  2. echo 'Current IP Address: ' . $_SERVER['REMOTE_ADDR'];
  3. ?>

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: "Start Local Server" custom IP
« Reply #6 on: February 04, 2014, 03:54:28 AM »
You don't use it in Unity.

You put it up on a web server that everyone can access.

GantZ_Yaka

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 21
    • View Profile
Re: "Start Local Server" custom IP
« Reply #7 on: February 06, 2014, 10:45:18 PM »
thanks for the answer, please answer another question.  When I start on different computers, a lot of servers, why TNLobbyClient.knownServers.list.size variable always returns 1, instead of the actual number of servers. What should I change in the TN's scripts to fix it? help me pls.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: "Start Local Server" custom IP
« Reply #8 on: February 06, 2014, 10:50:11 PM »
TNLobbyClient returns you the list of servers it knows about. If all servers register with the same lobby, and you are connected to that lobby, that list will be the list of servers from the server. If you are not connected to the lobby, or if you are connected to different lobby servers, then it will not contain all the servers.