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

Author Topic: HTML etc crashes program when no internet connection present  (Read 14636 times)

0 Members and 1 Guest are viewing this topic.

Joshua Flynn

  • Full Member
  • ***
  • Posts: 133
    • View Profile
HTML etc crashes program when no internet connection present
« on: April 24, 2012, 10:51:21 pm »
I would have assumed that the HTML side of SFML would have a fail-safe (I.E. return NULL string, error state, etc) for not being connected to the internet (given this could easily occur) or when a website is not available (which can also easily occur during downtime).

Given I am trying to run an automated program to automatically download data from a website that doesn't archive data (and both the internet connect and the website can fail)...

How do you check for the lack of an internet connection, and how do you check for whether or not the website is there, without SFML crashing the program? Surely this was a consideration?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10820
    • View Profile
    • development blog
    • Email
Re: HTML etc crashes program when no internet connection present
« Reply #1 on: April 25, 2012, 12:53:30 am »
I have no idea what you mean with 'the HTML side of SFML'. SFML does not have anything that relates to HTML.

So I guess you're trying to connect to a server and download something and the connection should get established by SFML?
In that matter I guess you're using sf::TcpSocket. Further on I guess you're using the connect(...) function which in fact returns a enum Status with which you can check if the connection failed.
For the part where the 'HTML can fail' I can't guess there what you're doing...

Provide some code otherwise we can't help you and just make lucky guess into the blue.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: HTML etc crashes program when no internet connection present
« Reply #2 on: April 25, 2012, 08:16:31 am »
Quote
I have no idea what you mean with 'the HTML side of SFML'. SFML does not have anything that relates to HTML.
I guess he's talking about sf::Http.

Quote
How do you check for the lack of an internet connection, and how do you check for whether or not the website is there, without SFML crashing the program?
Could you please start by describing your problem, showing your code, etc. before assuming that it is a bug in SFML? ;)
Laurent Gomila - SFML developer

Joshua Flynn

  • Full Member
  • ***
  • Posts: 133
    • View Profile
Re: HTML etc crashes program when no internet connection present
« Reply #3 on: April 25, 2012, 04:06:44 pm »
Quote
I have no idea what you mean with 'the HTML side of SFML'. SFML does not have anything that relates to HTML.
I guess he's talking about sf::Http.

Quote
How do you check for the lack of an internet connection, and how do you check for whether or not the website is there, without SFML crashing the program?
Could you please start by describing your problem, showing your code, etc. before assuming that it is a bug in SFML? ;)

Laurent is correct here. I meant HTTP but I wrote HTML... even though they are completely different things.

I took a look through and found I had a captain stupid moment (a string is not an array). I seem to making a lot of these. Thank you for the help. I thought it was weird (I didn't think SFML would be unstable).

Joshua Flynn

  • Full Member
  • ***
  • Posts: 133
    • View Profile
Re: HTML etc crashes program when no internet connection present
« Reply #4 on: April 25, 2012, 04:48:37 pm »
I still want to ask, is there a way to test if there is a working internet connection in SFML?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: HTML etc crashes program when no internet connection present
« Reply #5 on: April 25, 2012, 04:52:41 pm »
Quote
I still want to ask, is there a way to test if there is a working internet connection in SFML?
What about launching a connection to the remote host and checking if it fails?
Laurent Gomila - SFML developer

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Re: HTML etc crashes program when no internet connection present
« Reply #6 on: April 25, 2012, 05:31:09 pm »
I took a look through and found I had a captain stupid moment (a string is not an array). I seem to making a lot of these.
Maybe they'll happen less frequently if you don't use arrays, but instead STL containers ;)
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Joshua Flynn

  • Full Member
  • ***
  • Posts: 133
    • View Profile
Re: HTML etc crashes program when no internet connection present
« Reply #7 on: April 25, 2012, 08:47:18 pm »
Quote
I still want to ask, is there a way to test if there is a working internet connection in SFML?
What about launching a connection to the remote host and checking if it fails?

How would I check if it fails? Bear in mind I'm dealing with a dual problem where either the internet connection can fail whilst I'm not there, or the website itself can go down (and give the faux-pas impression it's an internet connection failure). I'm trying to write a program where it can attempt to correct numerous issues itself as I might be away from it for hours.

On a similar note, I'm trying to access my router via HTTP - which seems valid enough, but I am unsure how to transmit the authorisation for it? Fiddler2 suggests it's in the header, but I tried duplicating Fiddler2's setup for the authorisation and I only get a 400 (Bad Request) instead of a 401 (Authorisation Error). Any hints?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: HTML etc crashes program when no internet connection present
« Reply #8 on: April 25, 2012, 08:50:54 pm »
Quote
How would I check if it fails? Bear in mind I'm dealing with a dual problem where either the internet connection can fail whilst I'm not there, or the website itself can go down (and give the faux-pas impression it's an internet connection failure). I'm trying to write a program where it can attempt to correct numerous issues itself as I might be away from it for hours.
Ok, then why not just resend the request as long as it returns a connection error?

Quote
On a similar note, I'm trying to access my router via HTTP - which seems valid enough, but I am unsure how to transmit the authorisation for it? Fiddler2 suggests it's in the header, but I tried duplicating Fiddler2's setup for the authorisation and I only get a 400 (Bad Request) instead of a 401 (Authorisation Error). Any hints?
I have no idea, I haven't looked at authorization support for SFML yet.
Laurent Gomila - SFML developer

Joshua Flynn

  • Full Member
  • ***
  • Posts: 133
    • View Profile
Re: HTML etc crashes program when no internet connection present
« Reply #9 on: April 25, 2012, 08:56:13 pm »
I took a look through and found I had a captain stupid moment (a string is not an array). I seem to making a lot of these.
Maybe they'll happen less frequently if you don't use arrays, but instead STL containers ;)

Not really, given this was merely a programming typo. I don't think STL containers can prevent programming typos - it's never as good as people claim it to be.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10820
    • View Profile
    • development blog
    • Email
Re: HTML etc crashes program when no internet connection present
« Reply #10 on: April 25, 2012, 09:03:46 pm »
Could you please start by describing your problem, showing your code, etc. before assuming that it is a bug in SFML? ;)

I've never used sf::Http so I still could be wrong. ;D

If the website goes down or to be precise the webserver can not be reached anymore and you're performing a request, you'll receive a sf::Response which has a function getStatus() with which you can figure out what exactly went wrong (sf::Status::ConnectionFailed or sf::Status::NotFound).

I assume the problem now is that you can't tell if it's the connection of the client that is disconnected or the one from the server. In this case you could try to reach your server (or any server that you know of should always be online) with sf::TcpSocket. If this fails you know it's the internet connection of the client. If this succeeds you can try your http requests and check the response.

For you authentification problem, you'll have to read a bit about http header authentification but it shouldn't be that hard.
Wikipedia article...
« Last Edit: April 25, 2012, 09:07:53 pm by eXpl0it3r »
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Joshua Flynn

  • Full Member
  • ***
  • Posts: 133
    • View Profile
Re: HTML etc crashes program when no internet connection present
« Reply #11 on: April 25, 2012, 09:05:18 pm »
Ok, then why not just resend the request as long as it returns a connection error?

In the case of an internet connection failure, I'd like it to attempt to fix the failure (which might be a result of changing IPs and failing mid-way through). In this case it'd have to call RenewIP.

In the rare case of the website blocking, it actually has to change it's own IP (and it appears to have to connect directly to the router to make it reboot long enough to get a new IP assigned). The reason is, I'm running a program that archives ionospheric data from a website every 5 minutes, but it seems to be flagging up anti-denial of service attacks (I don't think once every 4-5 minutes is that severe?), of which a new IP would bypass.

Whilst normally I wouldn't raise the merits, I am trying to gather data so I can analyse the ionospheric patterns to see if they preclude earthquake events. But that's nigh on impossible if the website blocks me for hours on end (they don't even archive their own data - so every piece lost is lost permanently).

Last time I tried to contact them I didn't get a reply, so I'm not holding my breath.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: HTML etc crashes program when no internet connection present
« Reply #12 on: April 25, 2012, 10:39:28 pm »
I think eXpl0it3r's solution might be the best to know whether it's you or the host which is broken. The socket has no way to know this, so the only way is to check another (valid) host.
Laurent Gomila - SFML developer

Joshua Flynn

  • Full Member
  • ***
  • Posts: 133
    • View Profile
Re: HTML etc crashes program when no internet connection present
« Reply #13 on: April 29, 2012, 01:44:35 am »
I think eXpl0it3r's solution might be the best to know whether it's you or the host which is broken. The socket has no way to know this, so the only way is to check another (valid) host.

Problem is, I need a website I know won't be down, so it's a bit of a catch there.

Conversely, in my time away, I've discovered telnet, learned about it, wrote a class to communicate with it, can reboot my router at will (and issue whatever other commands I'd prefer, including running a script of commands), and can now send emails to my (or any other, depending) yahoo account without flagging up spam filters, now with the intention of forming an email communication system between me and my program, and perhaps an email alert system.

All I wanted to do was change IPs.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10820
    • View Profile
    • development blog
    • Email
Re: HTML etc crashes program when no internet connection present
« Reply #14 on: April 29, 2012, 10:48:05 pm »
Problem is, I need a website I know won't be down, so it's a bit of a catch there.

Try http://www.google.com/  ;D
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

 

anything