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 - tuckidart

Pages: [1]
1
Network / Re: AW: Server crashes when using packets
« on: June 12, 2015, 12:47:54 am »
Have you attempted to debug it yourself first?

If I try to debug it on Visual Studio, I can only open an instance of Server OR a Client at a time - to open both, I need to open the executable on the project's folder. As the problem is occurring after the connection is established, I could not debug it properly to see where the error is.

2
Network / Server crashes when using packets
« on: June 11, 2015, 08:21:35 pm »
Guys, I'm facing a trouble while trying to send packets. I open two instances of the same project in the same machine - the first one is set as Server and the second one as Client. When the connection is established, the Server instance of the project crashes. Could you please check the code below and tell me what's going on?

sf::TcpSocket socket;

int main()
{
    Server server;

    sf::Packet j0;
   
    if (eServer == true) // boolean indicating if it's the server or a client
    {
        sf::TcpListener listener;
        listener.listen(2000);
        listener.accept(socket);

        j0 << server.player1.attack << server.player1.defense << server.player1.name << server.player2.attack << server.player2.defense << server.player2.name;
       
        socket.send(j0);

        while (servLoop == true)
        {
            // server keeps running while the game happens
        }
    }
    else
    {
        socket.connect(sf::IpAddress::getLocalAddress(), 2000);

        Client client(width, height, title); // client's class

        int atk, def;
        std::string name;

        socket.receive(j0);
   
        j0 >> atk >> def >> name;

        client.setPlayer(atk, def, name);
       
        while (client.getWindow().isOpen())
        {
            sf::Event event;

            while (client.getWindow().pollEvent(event))
            {
                if (event.type == sf::Event::Closed){ c.getWindow().close(); }

                client.getWindow().clear();
                client.game();  // where the game happens
                client.getWindow().display();
            }
        }
    }
   
    return 0;
}

Pages: [1]
anything