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

Author Topic: Why is my server not receiving more than one packet?  (Read 3721 times)

0 Members and 1 Guest are viewing this topic.

MthDc

  • Newbie
  • *
  • Posts: 8
    • View Profile
Why is my server not receiving more than one packet?
« on: May 04, 2013, 03:40:43 pm »
I'm trying out SFML networking for the first time, and I've only got experience with networking in Java. While there are obviously similarities, I'm a bit confused about why this code doesn't work:

<--snip--> I have posted a new question in this thread <--snip-->
« Last Edit: May 05, 2013, 05:03:42 pm by MthDc »

AlexAUT

  • Sr. Member
  • ****
  • Posts: 396
    • View Profile
Re: Why is my application freezing and are my clients not connecting?
« Reply #1 on: May 04, 2013, 08:26:16 pm »
You are creating your thread in a local scope in your server application, so your threads gets "instantly" deleted. Look at http://www.sfml-dev.org/tutorials/2.0/system-thread.php command mistakes, it´s exactly your problem.

Your sf::Thread has to be a member of the GameServer class.


AlexAUT
« Last Edit: May 05, 2013, 05:55:15 pm by AlexAUT »

MthDc

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Why is my application freezing and are my clients not connecting?
« Reply #2 on: May 04, 2013, 08:27:24 pm »
That's embarassing. I didn't scroll down the entire page. Thanks!

AlexAUT

  • Sr. Member
  • ****
  • Posts: 396
    • View Profile
Re: Why is my application freezing and are my clients not connecting?
« Reply #3 on: May 04, 2013, 08:30:01 pm »
Quote
. I didn't scroll down the entire page.

Yeah, maybe Laurent should insert a index at the top of every tutorial, like wikipedia does.



AlexAUT
« Last Edit: May 04, 2013, 08:33:42 pm by AlexAUT »

MthDc

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Why is my application freezing and are my clients not connecting?
« Reply #4 on: May 05, 2013, 02:40:57 pm »
I have another question (didn't want to make another topic for it to avoid flooding the forums ;)). For some reason my server only accepts one packet from each client.
I have this code in the server file:

while(true)
        {
                sf::Packet packet;
                if(client_one->receive(packet) == sf::Socket::Done)
                {
                        std::string s;
                        packet >> s;
                        std::cout << "CLIENT_ONE: " << s << std::endl;
                }
                if(client_two->receive(packet) == sf::Socket::Done)
                {
                        std::string s;
                        packet >> s;
                        std::cout << "CLIENT_TWO: " << s << std::endl;
                }
        }

Which recieves the first packet from each client, but no packets which are sent later. Debugging the application seems to indicate the while(true) ends somehow! What could be the issue?
« Last Edit: May 05, 2013, 02:49:47 pm by MthDc »

AlexAUT

  • Sr. Member
  • ****
  • Posts: 396
    • View Profile
Re: Why is my server not receiving more than one packet?
« Reply #5 on: May 05, 2013, 05:19:42 pm »
I guess your sockets are in non-blocking mode, and this while-loop happens in a thread? Am I right?


If yes, i think your thread gets destroyed, maybe your GameServer class instance gets destroyed? Because your code example should work.


AlexAUT


MthDc

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Why is my server not receiving more than one packet?
« Reply #6 on: May 05, 2013, 06:33:18 pm »
The listener socket on the server is in non-blocking mode, the rest is in blocking mode.
I have allocated the server on the heap and made sure to delete it only after sending the packets, and there was still no output, so that isn't the issue. :/

AlexAUT

  • Sr. Member
  • ****
  • Posts: 396
    • View Profile
Re: Why is my server not receiving more than one packet?
« Reply #7 on: May 05, 2013, 07:26:44 pm »
Hmm, can you send some more code? Because this example doesn't represent your error.


btw there is a logic error in your code: Because your sockets are in blocking mode your server can't receive two packets from one client without receiving a packet from the other client.

AlexAUT

MthDc

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Why is my server not receiving more than one packet?
« Reply #8 on: May 05, 2013, 09:21:22 pm »
Thanks to your statement I managed to get this example working (by making them non-blocking). I interpreted the 'blocking state' wrongly in the tutorial: I thought it meant something different.

It doesn't work in my game project though, just in a little text based example. But I'll try to make it work :)

 

anything