Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - imnotarobot

Pages: [1]
1
Network / Re: How to reconnect a socket.
« on: October 06, 2022, 07:57:31 pm »
The fix for this was to temporarily change the socket to blocking to re-establish the connection. My game loop then changed it back to false so packets can be received when there is data.

2
Network / How to reconnect a socket.
« on: October 06, 2022, 06:51:44 pm »
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();

Pages: [1]