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

Author Topic: Test if TcpSocket exists  (Read 1924 times)

0 Members and 1 Guest are viewing this topic.

Toboxos

  • Newbie
  • *
  • Posts: 1
    • View Profile
Test if TcpSocket exists
« on: December 04, 2014, 09:50:34 pm »
Hello,

i want to write a little Chat. I have the class user which contain a sf::TcpSocket. If a user connect the i set the TcpSocket. But if the user doesnt already connect and i try to send him a message my programm crashes. Can i check if the Socket is valid?
Thanks for answers

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: Test if TcpSocket exists
« Reply #1 on: December 04, 2014, 10:17:06 pm »
It's not really clear what you're asking.  Could you provide a complete and minimal code example, or at least describe the problem in terms of specific SFML functions rather than vague phrases like "set the socket" and "send a message"?

A handful of things you might have been trying to ask (which are covered in the tutorial):
- Can I check whether a connect()/listen()/accept()/etc call was successful? Yes, they all return a status you can and should check.
- Can I check whether the code on a different machine successfully called those functions? No, because it's a different program, running on a different machine. All you can ever do is try to send a message to it and hope you eventually receive some kind of response.
- My program crashes when those functions fail; how do I stop that? Those functions should never *crash* as far as I know; this would indicate something is very wrong with your computer or your program.
- My program hangs when those functions fail; how do I stop that? Use non-blocking sockets or the optional timeout parameter.
« Last Edit: December 04, 2014, 10:18:59 pm by Ixrec »