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

Author Topic: Server crashes when using packets  (Read 1900 times)

0 Members and 1 Guest are viewing this topic.

tuckidart

  • Newbie
  • *
  • Posts: 2
    • View Profile
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;
}

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10991
    • View Profile
    • development blog
    • Email
AW: Server crashes when using packets
« Reply #1 on: June 11, 2015, 10:20:08 pm »
Have you attempted to debug it yourself first?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

tuckidart

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: AW: Server crashes when using packets
« Reply #2 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.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10991
    • View Profile
    • development blog
    • Email
Re: Server crashes when using packets
« Reply #3 on: June 12, 2015, 01:00:16 am »
You can debug one mode and then the other and see what goes on.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/