SFML community forums

Help => Network => Topic started by: Toboxos on December 04, 2014, 09:50:34 pm

Title: Test if TcpSocket exists
Post by: Toboxos 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
Title: Re: Test if TcpSocket exists
Post by: Ixrec 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.