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

Author Topic: Unexpected SocketSelector behavior  (Read 2750 times)

0 Members and 1 Guest are viewing this topic.

ZamenWolk

  • Newbie
  • *
  • Posts: 5
    • View Profile
    • Email
Unexpected SocketSelector behavior
« on: October 10, 2014, 12:22:08 am »
Hello everyone :)

I'm here today to seek help for my program that I've been coding for quite a bit now, and I've been stuck for about a week over a very annoying bug, and I'm here because I really don't know what to do anymore. My problem is that my socket selector always returns "false" immediatly when I call wait(), no matter if there is actually someone trying to connect on the listener, or if I put a timeout argument.I'm really out of ideas about what it could be, so any help would be more than welcome :)

EDIT : There's a much simpler version of the code 2 posts below :)

Here's my code :

main.cpp
(click to show/hide)

FightSubserver.hpp
(click to show/hide)

FightSubserver.cpp
(click to show/hide)

ServerClient.hpp
(click to show/hide)

In case you want to see the functor, here is functor.hpp
(click to show/hide)

And thank you in advance for your help :)

Zamen
« Last Edit: October 10, 2014, 01:03:57 pm by ZamenWolk »

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Re: Unexpected SocketSelector behavior
« Reply #1 on: October 10, 2014, 12:41:01 am »
Please read this post carefully :)
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

ZamenWolk

  • Newbie
  • *
  • Posts: 5
    • View Profile
    • Email
Re: Unexpected SocketSelector behavior
« Reply #2 on: October 10, 2014, 12:50:42 am »
Ahah yeah that's probably right, will do :) I'll come back with something better

ZamenWolk

  • Newbie
  • *
  • Posts: 5
    • View Profile
    • Email
Re: Unexpected SocketSelector behavior
« Reply #3 on: October 10, 2014, 01:03:05 pm »
So I have updated my project os it's wayyy more simple, but there is still the error bothering me

main.cpp
bool aboutToStop = false;

int main()
{
    TcpListener             listener;
    unsigned int            subserverNumber(50);
    vector<TcpSocket*>      clientsVector;
    SocketSelector          selector;

    for (int i = 0; i < subserverNumber; i++)
    {
        TcpSocket* newSocket = new TcpSocket;
        clientsVector.push_back(newSocket);
    }

    selector.add(listener);

    //Addition of all the sockets to the selector
    for (int i = 0; i < clientsVector.size(); i++)
    {
        selector.add(*clientsVector[i]);
    }

    listener.listen(2715);

    cout << "The server host is now ready and working !" << endl;

    while (!aboutToStop)
    {
        cout << "Searching for event" << endl;

        if (selector.wait())
        {
            cout << "Found something !" << endl;
        }
        else
        {
            cout << "Couldn't find anything" << endl;
        }

        sf::sleep(sf::milliseconds(25));
    }

    return EXIT_SUCCESS;
}

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Unexpected SocketSelector behavior
« Reply #4 on: October 10, 2014, 03:10:01 pm »
The listener must be added to the selector after the call to listen(). Same for all your TcpSockets, they must be connected before being added to the selector. But honestly I have no idea what you're going to do with 50 empty sockets. Why don't you create them on the fly, on each new connection?
Laurent Gomila - SFML developer

 

anything