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

Author Topic: How to manage NO Internet Connection?  (Read 3177 times)

0 Members and 1 Guest are viewing this topic.

alessandroAmedei

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
How to manage NO Internet Connection?
« 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.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: How to manage NO Internet Connection?
« Reply #1 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.
Laurent Gomila - SFML developer

alessandroAmedei

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
Re: How to manage NO Internet Connection?
« Reply #2 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.


« Last Edit: July 17, 2017, 11:23:23 am by alessandroAmedei »

dabbertorres

  • Hero Member
  • *****
  • Posts: 506
    • View Profile
    • website/blog
Re: How to manage NO Internet Connection?
« Reply #3 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).

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: How to manage NO Internet Connection?
« Reply #4 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 ;)
Laurent Gomila - SFML developer

 

anything