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

Author Topic: accepting a socket that has already been accepted  (Read 4810 times)

0 Members and 1 Guest are viewing this topic.

iride

  • Jr. Member
  • **
  • Posts: 88
    • View Profile
    • Email
accepting a socket that has already been accepted
« on: April 15, 2015, 06:20:57 am »
 What happens when I accept a socket that has already been accepted?
will it just continue to return sf::Socket::Done?
listener.accept(socket); //accepted
listener.accept(socket); //??

« Last Edit: April 15, 2015, 06:25:48 am by iride »

Gambit

  • Sr. Member
  • ****
  • Posts: 283
    • View Profile
Re: accepting a socket that has already been accepted
« Reply #1 on: April 15, 2015, 11:12:43 am »
Why would you need to do this? If a socket has been accepted, any request to be re-accepted will be ignored until the original connection is terminated. Do not confuse a socket connection with a connection from the same computer. A single computer can have multiple socket connections to the same server.

binary1248

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1405
  • I am awesome.
    • View Profile
    • The server that really shouldn't be running
Re: accepting a socket that has already been accepted
« Reply #2 on: April 15, 2015, 11:23:48 am »
Like Gambit already said, there is little reason to do this in practice, especially if like in your example, those 2 statements are really executed one after the other.

The first statement will block until an incoming connection arrives and accept it into the socket object.

The second statement will block until an incoming arrives, disconnect the connection currently in the socket object, and populate it with the new connection.

What you essentially end up doing is prevent multiple connections from ever being processed simultaneously. As soon as another connection request arrives, the previous one will be disconnected. This is all disregarding the fact that if you are running this in a single thread, it would block your whole application until the second connection attempt is made anyway.

Just don't do this, it is not only bad practice, but it really has no purpose and might not even do what you expected.
SFGUI # SFNUL # GLS # Wyrm <- Why do I waste my time on such a useless project? Because I am awesome (first meaning).

iride

  • Jr. Member
  • **
  • Posts: 88
    • View Profile
    • Email
Re: accepting a socket that has already been accepted
« Reply #3 on: April 15, 2015, 08:38:44 pm »
If a socket has been accepted, any request to be re-accepted will be ignored until the original connection is terminated.

As soon as another connection request arrives, the previous one will be disconnected.

I think these are 2 conflicting responses. So does the previous connection get disconnected or not?


Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
Re: accepting a socket that has already been accepted
« Reply #4 on: April 15, 2015, 09:12:38 pm »
Binary's right: the socket is first closed and connected to the new source. (source)
SFML / OS X developer

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: accepting a socket that has already been accepted
« Reply #5 on: April 15, 2015, 10:57:53 pm »
Allow me to suggest some reading material: UNIX Network Programming.