I cannot connect to the own Team Fortress 2 server? Why

hostingteam-fortress-2technical-issues

Recently, I have been encountering an unusual problem with a testing TF2 server that I'm running on my local system. Namely, my client is completely unable to connect to the server. It does not appear on the LAN tab, and connecting it through connect localhost:27015 does absolutely nothing but time out.

The server is set up through srcds, with the following startup shell script:

#!/bin/sh
tf2/srcds_run -console \
    -game tf \
    -nohltv \
    +randommap \
    +maxplayers 24

The config file of the server is as follows:

hostname "Local_Dev_Server"
sv_contact "hello@hello.hello"
sv_pausable 1
sv_stats 0
sv_region 1
fps_max 600
sv_allowupload 1
sv_allowdownload 1

The server is (obviously) running on my local computer, primarily for development purposes. The server itself is running on Ubuntu 16.04 LTS, and is starting up normally. The console reports no strange errors other than the usual SRCDS warnings and/or irrelevant mod errors.

The server itself binds to port 27015:

Network: IP 127.0.1.1, mode MP, dedicated Yes, ports 27015 SV / 27005 CL

Attempts to connect directly (with the connect 127.0.1.1:27015 command) return this in the console:

] connect 127.0.1.1:27015
WARNING: Port 27015 was unavailable - bound to port 27016 instead
WARNING: Port 27005 was unavailable - bound to port 27006 instead
Network: IP 127.0.1.1, mode MP, dedicated No, ports 27016 SV / 27006 CL
m_face->glyph->bitmap.width is 0 for ch:32 TF2
m_face->glyph->bitmap.width is 0 for ch:32 TF2
m_face->glyph->bitmap.width is 0 for ch:32 Verdana
Connecting to 127.0.1.1:27015...
Retrying 127.0.1.1:27015...
Retrying 127.0.1.1:27015...
Retrying 127.0.1.1:27015...
Connection failed after 4 retries.

No entry shows in the server logs. netstat -tulpn | grep 27015 returns the following, showing the server is running and bound to the port:

tcp   0   0   127.0.1.1:27015   0.0.0.0:*  LISTEN  26665/srcds_linux
udp   0   0   0.0.0.0:27015     0.0.0.0:*          26665/srcds_linux

My system's firewall is blocking connections from the world (as this is only a local development server), but connections to/from the 127.0.0.0/8 subnet are all globally permitted. Similarly, debug utilities like netcat and telnet are able to connect to these ports, showing that they are in fact bound and accessible locally.

I've confirmed that this problem happens with both sv_lan 0 and sv_lan 1.

What am I doing wrong?

Best Answer

AIUI the client needs to listen on some port (usually 27015) on the loopback interface (why, I don't know). When you try to put the server on that same port, the client ends up moving to a different port, and for some reason, the two of them get confused. I run my server on my LAN IP, and then use iptables to control access. When working with closed-source software, it's usually easiest to manage security elsewhere :)