celeron55/minetest — Issue #27: search for the available port
Author: bookwar
Created: 2011-12-02 23:11:22+00:00
State: open

When port 30000 is already taken by some other application, one can not start new single player game (the one with empty Server field). And minetest gives the following output:
======================================================
AuthManager: loading from /home/bookwar/.minetest/world/auth.txt
BanManager: loading from /home/bookwar/.minetest/world/ipban.txt
6: Bind failed: Address already in use

In thread 7ffa4fb13700:
/builddir/build/BUILD/celeron55-minetest-bc0e5c0/src/connection.cpp:577: virtual void* con::Connection::Thread(): Assertion '0' failed.
Debug stacks:
DEBUG STACK FOR THREAD 7ffa4f312700:
#0 virtual void* ServerThread::Thread()
#1 void Server::Receive()
(Leftover data: #2 void Server::SendBlocks(float))
DEBUG STACK FOR THREAD 7ffa5ac20740:
#0 int main(int, char**)
(Leftover data: #1 void Server::start(short unsigned int))
Aborted
======================================================

I think the more "user-friendly" way to handle this is to find the new port number for the minetestserver instance.

So, before running the server on port 30000 the client program could check if this port is free to use. If not check the port 30001, 30002..