I'm trying my hand at a co op game and have a standalone server that also acts as a dungeon master.
If the server computer dies I want to give an in game option to 'try to reconnect' so I've assigned a key press to do this for testing.
On tab, the following function is called, basically the same function as on game start /logon. I will change this function somewhat, but I'm wondering why it doesn't connect a second time around when the server is back up. Is it related to using a socket that has previously disconnected etc. I've browsed through some of the docs but have missed it. To clarify this code works when initially connecting.
Thanks,
void Game::initConnection()
{
bool connect = false;
client.getIP();
while (!connect)
if (client.socket.connect(client.ip, 2000) == sf::Socket::Done)
{
connect = true;
std::cout << "Connection made\n ";
std::cout << "Connected to server \n " << client.socket.getRemoteAddress();
std::cout << "\nLocal port: " << client.socket.getLocalPort();
login();
}
else
std::cout << "probing for server\n / Connection needed to be established to run = false (edit InitConnection fuinction in game.cpp to change) " << sf::IpAddress::LocalHost << "3000\n";
clientSendID();