SFML community forums

Help => Network => Topic started by: MthDc on May 04, 2013, 03:40:43 pm

Title: Why is my server not receiving more than one packet?
Post by: MthDc 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 (http://en.sfml-dev.org/forums/index.php?topic=11373.msg79096#msg79096) in this thread <--snip-->
Title: Re: Why is my application freezing and are my clients not connecting?
Post by: AlexAUT 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
Title: Re: Why is my application freezing and are my clients not connecting?
Post by: MthDc on May 04, 2013, 08:27:24 pm
That's embarassing. I didn't scroll down the entire page. Thanks!
Title: Re: Why is my application freezing and are my clients not connecting?
Post by: AlexAUT 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
Title: Re: Why is my application freezing and are my clients not connecting?
Post by: MthDc 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?
Title: Re: Why is my server not receiving more than one packet?
Post by: AlexAUT 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

Title: Re: Why is my server not receiving more than one packet?
Post by: MthDc 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. :/
Title: Re: Why is my server not receiving more than one packet?
Post by: AlexAUT 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
Title: Re: Why is my server not receiving more than one packet?
Post by: MthDc 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 :)