SFML community forums

Help => Network => Topic started by: alessandroAmedei on July 16, 2017, 01:56:01 pm

Title: How to manage NO Internet Connection?
Post by: alessandroAmedei on July 16, 2017, 01:56:01 pm
Hi, i would like to allert the client that there is not internet connection. The problem is that when i try to se the host in a http object, the process stuck, and i can't even catch an std::exception.
How can i get if there is not internet connection? Thank you.
Alessandro Amedei, Florence.
Title: Re: How to manage NO Internet Connection?
Post by: Laurent on July 16, 2017, 05:05:01 pm
You can try to connect a TCP socket to a reliable host (for example www.google.com), but be careful when you choose your timeout.
Title: Re: How to manage NO Internet Connection?
Post by: alessandroAmedei on July 17, 2017, 11:17:14 am
Thank you for your answer.

I tried like this:

(click to show/hide)

I don't care about the time out, it can also take some seconds (or i can set a notblock socket).
The problem is the same, when i turn off my wifi, the process stucks at socket.connect(..).

UPDATE
I found out that the problem occurs when or the wifi module is off or when it is not connected to a wireless network.
So by now i need a is connected to a network, not to a server. Any ideas?   :)


Thank you!

Alessandro Amedei, Florence.


Title: Re: How to manage NO Internet Connection?
Post by: dabbertorres on July 18, 2017, 02:57:58 am
No, the timeout is for that reason.
If you don't want it to block until it can connect, you must provide a timeout - so that it will "give up". That's more or less the only solution (in this case).
Title: Re: How to manage NO Internet Connection?
Post by: Laurent on July 18, 2017, 06:35:47 am
Quote
If you don't want it to block until it can connect, you must provide a timeout - so that it will "give up".
There's always a timeout, the OS never lets a socket try to connect forever ;)