Author Topic: [SOLVED] Connecting to lobby server to get server list?  (Read 4554 times)

MCoburn

  • Jr. Member
  • **
  • Thank You
  • -Given: 1
  • -Receive: 7
  • Posts: 69
    • View Profile
[SOLVED] Connecting to lobby server to get server list?
« on: September 23, 2014, 11:26:47 PM »
I'm trying to poll the TNet Lobby server for the list of servers, so my players can click one to join.

On my gameobject that controls the main menu, I've assigned the "TNet Network Manager" script and a "TNUdp Lobby Client". In the latter, I set the lobby server to my remote box's hostname (it's a Amazon Micro Win2K12) and made sure Windows Firewall allows the compiled binary (I took the one included with the UnityPackage and did some minor adjustments). Server ports are 31337, 31338 and 31339.

Here's what the current gameobject looks like. Hostname obscured for privacy/security reasons.


When clicking play, this comes out of the console:
  1. [TNet] Local IPs: 1
  2.   1: 192.168.0.9 (Primary)
  3. UnityEngine.Debug:Log(Object)
  4. TNManager:Awake() (at Assets/TNet/Client/TNManager.cs:905)
  5.  

Which I assume means that TNet is awake. Sometimes the UPNP Gateway says "Not found, can't open ports automatically", sometimes it's quiet, sometimes it reports back the gateway IP. Dunno if that's a issue with a stuck port, or what. Now, in the code...

  1. void Start() {
  2. TNManager.client.packetHandlers[(byte)Packet.ResponseChannelList] = OnChannelList;
  3. refreshHostList();
  4. }
  5. <....>
  6. void refreshHostList(){
  7. isBusy = true;
  8.         TNManager.client.BeginSend(Packet.RequestChannelList);
  9.         TNManager.client.EndSend();
  10. }
  11.  
  12. void OnChannelList (Packet response, BinaryReader reader, IPEndPoint source){
  13.         Debug.Log("If you can see this, we have channels. Maybe.");
  14.         // The first integer represents the number of entries to follow
  15.         int channels = reader.ReadInt32();
  16.  
  17.         // Read all incoming channel data
  18.         for (int i = 0; i < channels; ++i)
  19.         {
  20.             int id              = reader.ReadInt32();
  21.             int players         = reader.ReadUInt16();
  22.             int limit           = reader.ReadUInt16();
  23.             bool pass           = reader.ReadBoolean();
  24.             bool persistent     = reader.ReadBoolean();
  25.             string level        = reader.ReadString();
  26.             string data         = reader.ReadString();
  27.  
  28.             // TODO: Do something with this data here
  29.         }
  30. isBusy = false;
  31. }
  32.  
The OnChannelList code was pulled from here with a slight edit to see if TNet will actually get the stuff. However, it never says the Debug output.

I'm baffled at what I need to do. Do I need to use TNManager.Start(port) to start listening for info between the server and client? Or what am I missing? Note that a good chunk of the code is cut out because I'm not going to paste the entire script.

PRE-POST EDIT: Okay, so I switched to TCP Lobby Client and it seems to be better. However, on the server, I'm getting things like:
  1. <my public dev box IP>:<randomport> has connected.
  2. <my public dev box IP>:<randomport> has timed out.
  3. <my public dev box IP>:<randomport> has disconnected.
  4. <my public dev box IP>:<old port plus 2> has connected.
  5. <.....>
  6.  


At least this output is better than nothing, that's for sure.
Can anyone provide pointers on what could possibly be going wrong?
« Last Edit: September 30, 2014, 12:48:49 AM by MCoburn »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Connecting to lobby server to get server list?
« Reply #1 on: September 24, 2014, 03:02:56 PM »
Amazon blocks UDP for security reasons. You have to use TCP.

Disconnect happens after a period of inactivity. Your client needs to ping the server every so often to let the server know that the connection is still active. TNet does this automatically by default, but only if the application is set to "run in background".

P.S. BeginSend/EndSend can be called on the TNManager itself, there is no need to have a 'client' in there.
  1.                 TNManager.BeginSend(Packet.RequestChannelList);
  2.                 TNManager.EndSend();

MCoburn

  • Jr. Member
  • **
  • Thank You
  • -Given: 1
  • -Receive: 7
  • Posts: 69
    • View Profile
Re: Connecting to lobby server to get server list?
« Reply #2 on: September 24, 2014, 08:53:06 PM »
I would appreciate some sample code, as I cannot get this working as intended. Even on my own development box, the Lobby server sees the client, but has the "Connect, Time Out, Disconnect" cycle. OnNetworkConnect() doesn't return anything helpful. Even using the stock lobby server that comes with TNet without any mods still has the same issue. ???

I am almost tempted to say that 1.9.9's lobby server build is broken.

EDIT: New scene, 2 objects (Camera and gameObject). GameObject has 2 scripts: Network Manager and TCP Lobby Client. No additional scripts. Just those.
TNET Lobby Server standalone running on 5127 - 5129 (default TNet TCP/UDP Ports). Still getting this:
  1. Local IPs: 1
  2.   1: 192.168.0.9 (Primary)
  3.  
  4. Gateway IP:  192.168.0.1
  5. External IP: 59.x.x.9
  6.  
  7. UDP Lobby Server started on port 5129 using interface 0.0.0.0
  8. Game server started on port 5127 using protocol version 12
  9. Press 'q' followed by ENTER when you want to quit.
  10.  
  11. UPnP: TCP port 5127 was opened successfully.
  12. UPnP: UDP port 5128 was opened successfully.
  13. UPnP: UDP port 5129 was opened successfully.
  14. 127.0.0.1:52342 has connected
  15. 127.0.0.1:52342 has timed out
  16. 127.0.0.1:52342 has disconnected
  17. 127.0.0.1:52350 has connected

EDIT 2: I can kill the server ('Q' in console and ENTER) which will spit out "A connection was forcibly disconnected" followed by "No connection was able to be made due to the target machine actively rejecting it". So some how it does handle the connection, but never establishes it fully. Could I roll back to a older version of TNet to confirm if something broke?

I'm going to put the tools down for the rest of the day. I bet it's something I'm overlooking.
« Last Edit: September 24, 2014, 09:45:33 PM by MCoburn »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Connecting to lobby server to get server list?
« Reply #3 on: September 25, 2014, 07:58:18 PM »
Hmm, well just to be on the safe side I'm going to push another update with some more changes and everything recompiled.

MCoburn

  • Jr. Member
  • **
  • Thank You
  • -Given: 1
  • -Receive: 7
  • Posts: 69
    • View Profile
Re: Connecting to lobby server to get server list?
« Reply #4 on: September 25, 2014, 10:00:02 PM »
I solved the issue, with the help of Aren over skype. I needed to pass the -tcpLobby <porthere> to the server for it to work. Then, I realized that I was connecting to the gameserver port instead of the lobby port! After fixing this, I checked the vars in the code:

  1. TNTcpLobbyClient.isActive is true.
  2. TNTcpLobbyClient.error is null/empty. (This changes with the error message if I kill the server via 'q' and enter or close the window).
  3. TNTcpLobbyClient.knownServers.list.size is 0.
  4.  

The question is now, will that server list be updated as soon as a new server gets registered to the lobby server (the standalone TNet executable)?
Since that's out the way, now I can focus on actual server logic. Woohoo!

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Connecting to lobby server to get server list?
« Reply #5 on: September 27, 2014, 07:38:09 PM »
TCP lobby server sends server changes to all connected clients, so yes. UDP lobby server updates are periodic instead.