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

Author Topic: Advice, properly using/stopping a tcp listener.  (Read 3942 times)

0 Members and 1 Guest are viewing this topic.

doingit

  • Newbie
  • *
  • Posts: 17
    • View Profile
Advice, properly using/stopping a tcp listener.
« on: February 23, 2016, 08:31:13 am »
As we all know, the tcplistener, while accepting new sockets, go into a long wait mode.

I've gotten around this using sf::Thread, allowing me to work while the thread continuously acquire more clients.

Problem is, when I'm done with the app, I am unable to close the app properly because the other thread is still running.(thread.wait() with sfml's sf::thread and thread.join with std::thread)

What could I do to forcefully close a listen operation?

If not close it, how would I go around not allowing it to accept sockets when in fact, I may still be including more clients.

Say for example, a 12 player game that allows players to join and leave the game whenever they feel.

It would be easier to just queue up 12 players, then start with the network no longer listening for players connecting, but that isn't the path that I am designing. Any ideas?

I am still trying non-blocking, but am receiving random behavior (sometimes it'll stop at accepting, other times, not), will update if I figure it out.

Edit:
Ha.. just thought of something funny, maybe I can attempt to reconnect to it, allowing it to pass the accepting socket stage (of course my socket would be thrown away since I am already registered) and thus allowing it to complete the cycle, and exiting the loop due to running = false. Trying it.

Edit 2:
Solved, I was able to exit the listener and program by attempting a final connection to the server, allowing it to pass the listening method and complete the loop, joining up with main, then exiting. Strange approach, but it works.
« Last Edit: February 23, 2016, 09:13:19 am by doingit »

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Advice, properly using/stopping a tcp listener.
« Reply #1 on: February 23, 2016, 04:16:37 pm »
TcpListener has a close function. Can this not be called from the main thread?
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Advice, properly using/stopping a tcp listener.
« Reply #2 on: February 23, 2016, 09:13:56 pm »
See this thread. As you see, there has been disagreement about the utility of this feature.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development: