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

Author Topic: socket is not being accepted by tcplistener  (Read 2165 times)

0 Members and 1 Guest are viewing this topic.

konig

  • Newbie
  • *
  • Posts: 7
    • View Profile
    • Email
socket is not being accepted by tcplistener
« on: June 01, 2014, 05:33:00 pm »
The program is huge.. so, I'm just pasting a very small part of it.

Case 1:
    sf::TcpListener listener;
    listener.listen(2001);
    sf::TcpSocket socket;
   std::cout<<"done1\n";
 


Case 2:
    sf::TcpListener listener;
    listener.listen(2001);
    sf::TcpSocket socket;
   std::cout<<"done1\n";
   listener.accept(socket);
   std::cout<<"done2\n";
 

Output for :
Case 1:
done1

Output for Case 2:
done1



done2 does not come in the output. and the program crashes.

Can somebody please tell me what might be going wrong, or where I should look for, for the the error?
Thanks in advance.

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: socket is not being accepted by tcplistener
« Reply #1 on: June 01, 2014, 05:44:00 pm »
What do you mean by "crashes"?  By default that function blocks until something connects to the socket, so if you just mean your program freezes/stops responding, that's because it's blocked.  Do you have another program trying to connect to that socket?

konig

  • Newbie
  • *
  • Posts: 7
    • View Profile
    • Email
Re: socket is not being accepted by tcplistener
« Reply #2 on: June 01, 2014, 07:15:56 pm »
Thank you.. as you said there was no error.
I got it.. the window  which I created closed, the program didn't.. the listener was waiting for connections from the socket.

One more request, do know any good multiplayer game making sources for sfml?

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: socket is not being accepted by tcplistener
« Reply #3 on: June 01, 2014, 07:27:12 pm »
Aside from the official tutorials and the book (which I assume has material on multiplayer), there's bound to be some games in the SFML Projects forum you can use as reference.

But most issues you'll run into apply to all multiplayer games, so anything on the internet should be helpful.  All SFML does is give you a simple, platform-agnostic interface for UDP and TCP sockets.