Author Topic: TNet TCP lobby on Amazon EC2  (Read 6909 times)

Goost91

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 5
    • View Profile
TNet TCP lobby on Amazon EC2
« on: December 03, 2013, 09:25:23 AM »
Hi,

I'm trying to set up a lobby server on an Amazon EC2 server, but the lobby server isn't working.
It's running fine, and I checked whether the data is being received through tcpdump, which is receiving data.

However, the lobby server doesn't register any new servers, which completely breaks the lobby functionality within the game I'm working on.

What could be the issue? Is it something to do with the specific Linux distro I'm using (the default Amazon one)?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: TNet TCP lobby on Amazon EC2
« Reply #1 on: December 03, 2013, 10:40:21 AM »
So which part is not working exactly? Can you see people connect from the outside? How do you start the lobby server? (what command?)

Goost91

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 5
    • View Profile
Re: TNet TCP lobby on Amazon EC2
« Reply #2 on: December 03, 2013, 10:45:06 AM »
So which part is not working exactly? Can you see people connect from the outside? How do you start the lobby server? (what command?)
The servers aren't getting registered in the lobby server, normally I'd see a bunch of messages of servers being registered, which do not show up.
Because of this I can't actually connect to a different host in-game.

The way I launch the server is through the following shell script:
  1. #!/bin/sh
  2. exec /usr/bin/mono TNServer.exe -name "Test" -tcpLobby 5129 > "lobby.log"
I use this script mostly to ensure it keeps on running in the background, while still being able to see the log in realtime through tail -f

pyscho2day

  • Jr. Member
  • **
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 74
    • View Profile
Re: TNet TCP lobby on Amazon EC2
« Reply #3 on: December 03, 2013, 10:51:33 AM »
Did you make sure to open the port?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: TNet TCP lobby on Amazon EC2
« Reply #4 on: December 03, 2013, 09:04:11 PM »
With Amazon EC2 I had to open ports in two places -- on their web console, as well as disabling the firewall on the windows side. Since you're using linux, you still need to do the former. I don't know if there is anything in place of the latter.

Goost91

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 5
    • View Profile
Re: TNet TCP lobby on Amazon EC2
« Reply #5 on: December 04, 2013, 03:51:36 AM »
I've checked whether the port is open, and it is.
I also analyzed the network traffic through tcpdump by letting it listen on the port of the lobby server, and there were plenty of packets being received, so I'm pretty sure it is open.

Goost91

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 5
    • View Profile
Re: TNet TCP lobby on Amazon EC2
« Reply #6 on: December 04, 2013, 05:05:21 AM »
I've been testing various things out, and it seems to be something with the default Amazon linux instance.
I've tried the Ubuntu server image they provide, and it works, but there is one small problem: The servers disappear from the lobby after 5-10 seconds.

Why do they disappear? Shouldn't they stay registered as long as the server's online?

pyscho2day

  • Jr. Member
  • **
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 74
    • View Profile
Re: TNet TCP lobby on Amazon EC2
« Reply #7 on: December 04, 2013, 01:18:30 PM »
Make sure that you keep the object alive that started the server. If you don't the server will shut down. 

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: TNet TCP lobby on Amazon EC2
« Reply #8 on: December 04, 2013, 05:40:57 PM »
UDP lobby servers expect to be notified of the server status every few seconds. No updates mean the server gets removed. TCP lobby server will keep the server alive as long as the connection is alive and active. If you have "run in background" turned off and alt tab, your Unity will stop processing data, and the game will effectively disconnect.

Goost91

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 5
    • View Profile
Re: TNet TCP lobby on Amazon EC2
« Reply #9 on: December 05, 2013, 04:09:18 AM »
Weird thing is that the object stayed active, and the game is running in the background.

Oh well, after trying out several different machine images I found out that the server doesn't like being run on the background in Linux for some odd reason.
Whenever it's running on the foreground it works fine, whenever you run it in the background through the usual method, it doesn't work.

I did however find a workaround for that: open up a screen session and run the server through that. It'll keep the server running flawlessly.
If you want to make sure it runs everytime the instance is started, you basically add something like the following to your startup:
Quote
screen -S Lobby -d -m <command to launch the lobby server>

pyscho2day

  • Jr. Member
  • **
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 74
    • View Profile
Re: TNet TCP lobby on Amazon EC2
« Reply #10 on: December 05, 2013, 10:51:05 AM »
I wonder if it is because the server is trying to write to the screen and if it doesn't have one it doesn't know what to do.  I have had other game servers do that same thing in the past and just got accustomed to making sure that they have their own screen even if its detached at the time.

tiggus

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 6
    • View Profile
Re: TNet TCP lobby on Amazon EC2
« Reply #11 on: December 14, 2013, 01:02:32 AM »
I think it's the other way around, it's not the writing to STDOUT and STDERR that is the problem but the reading from STDIN that you can't background.

I'm in process right now of compiling new lobby server for Ubuntu and just took out the portion related to reading from keyboard to quit and seems to work fine. 

EDIT:  You do need to register a signal handler to achieve the Unix behavior, maybe there are other ways as well I am not sure.  The downside is this starts to get into platform specific code as this won't work on Windows to my knowledge.
« Last Edit: December 14, 2013, 02:12:13 AM by tiggus »

tiggus

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 6
    • View Profile
Re: TNet TCP lobby on Amazon EC2
« Reply #12 on: December 14, 2013, 02:02:27 AM »
Here is a snippet that illustrates how to catch the signals in ServerMain.cs:

  1. $gmcs TestDaemon.cs -r:Mono.Posix.dll
  2. $mono TestDaemon.exe > test.log &
  3. $ps -ef | grep TestDaemon
  4. root     30131 25533  0 23:54 pts/3    00:00:00 mono TestDaemon.exe
  5. $kill 30131
  6. [1]+  Done                    mono TestDaemon.exe > test.log
  7. cat test.log
  8. Initializing Handler for SIGINT and SIGTERM
  9. Caught SIGTERM signal, exiting.
  10.  

  1. using System;
  2. using System.Threading;
  3. using Mono.Unix;
  4. using Mono.Unix.Native;
  5.  
  6. class TestDaemon {
  7.         static void Main ()
  8.         {
  9.                 StartHandler();
  10.         }
  11.  
  12.         static void StartHandler()
  13.         {
  14.                 new Thread(TerminateHandler).Start();
  15.         }
  16.  
  17.         static void TerminateHandler()
  18.         {
  19.                 Console.WriteLine("Initializing Handler for SIGINT and SIGTERM");
  20.                 UnixSignal[] signals = new UnixSignal[]{
  21.                         new UnixSignal(Signum.SIGINT),
  22.                         new UnixSignal(Signum.SIGTERM),
  23.                 };
  24.  
  25.                 int caughtSignal = UnixSignal.WaitAny(signals);
  26.                 Console.WriteLine ("Caught {0} signal, exiting.",signals[caughtSignal].Signum);
  27.         }
  28. }
  29.