Web2.0 Reconnections

Got a question on Web2.0 and browser reconnections…

Web1.0 had gotten pretty good with automatically reconnecting to the web server if the server connection went down and later came back up. I mean it got really good.

With my first Web2.0 project, I see now see the below message:
image

But the reconnection never seems to occur. Is there a timeout limit? I have a digital signage player that is displaying this web app. If I have to reset the server, I have to then reset the signage player as well which is a pain. The old aggressive reconnect of Web1.0 worked much better for this. Is there a setting I am missing? Is there a way to make Web2.0 behave like that?

1 Like

I had some trouble with this early on and wrote a little JavaScript method to check for disconnects and reload the page when the server came back up. It uses a 10 second timeout, which can be changed in the last JS line. Put this in Session.Opening:

var exec() as String
exec.Add( "setInterval(function() {" )
exec.Add( "  if ($('#dialog_disconnect').length > 0 || $('#dialog_reconnect').length > 0) {" )
exec.add( "    $.ajax({url : window.location.href}).done(function(data, statusText, xhr) {" )
exec.add( "      if (xhr.status == 200) location.reload();" )
exec.Add( "    });" )
exec.Add( "  }" )
exec.Add( "}, 10000);" )
ExecuteJavaScript( String.FromArray( exec, "" ) )

Hope it helps. I haven’t used or tested it in a long while now.

1 Like

Cool. Where do you put this?

Edited that in just before you posted.

1 Like

:rofl: :joy: :rofl:

I see that now!

1 Like

Would be nice if Xojo fixed it so that it acts like Web1.0 did. That really was working well at the end.

1 Like

Put in a Feedback Case. I’ve not had any complaints or noticed any issues recently, but that may be down to how my users utilize the apps.

2 Likes

Done:

<https://xojo.com/issue/64156>

2 Likes

Anthony,

Your code detects when the connection to the server has come back but unfortunately, it doesn’t always load the page. Sometimes the webpage comes back like it should. Other times you just get white browser window after it loads.

Oh well, I guess I just have to wait for Xojo to implement my feature request…

Sounds like the location.reload is happening too quickly as the server is coming up.

Try this:

var exec() as String
exec.Add( "setInterval(function() {" )
exec.Add( "  if ($('#dialog_disconnect').length > 0 || $('#dialog_reconnect').length > 0) {" )
exec.add( "    $.ajax({url : window.location.href}).done(function(data, statusText, xhr) {" )
exec.add( "      if (xhr.status == 200) setTimeout(function() {location.reload();},10000);" )
exec.Add( "    });" )
exec.Add( "  }" )
exec.Add( "}, 10000);" )
ExecuteJavaScript( String.FromArray( exec, "" ) )
4 Likes

Well, this does reload the page but I am also seeing it kill the web app. I’m seeing it reload the page but then after the page is reloaded, the web app quits. Seems to fail silently. If I remove this code, then it is solid. Not sure if it is this code or something else…

Oh well…

It would have to be somewhere else. This operates entirely client-side and only when the connection is lost. Not sure what the other issue is or where it could be coming from, but it’s not this.
– Anthony

Interesting. Because when I have this running, the app quits just after reloading. I comment this out and things seem fine. What is odd is that I can’t get it to happen in the debugger.

Ah. Just after the page is loaded. I assumed you meant when the connection is lost the app quits. Let me take a look.

I can’t replicate this, so I have no idea what you’re seeing.

OK. Thanks. It could be on my end. It’s a silent failure so hard to trace. I’ll keep digging.

Yeah, there’s no JS errors, page reloads for me. No clue what might be going wrong.

OK. I think I might know what was happening. I threw in a number of calls to write data to a TextOutputStream as I was trying to track down a bug that I couldn’t figure out. I think what might have been happening is that with multiple clients attempting to reload data at the same time, it was causing an IO Exception to happen and I’ve seen times in the past when these happen silently. I’ve removed the code to write to the TextOutputStream and things seem a lot more stable with your code in place.

Glad to hear it!

You might want to try http://documentation.xojo.com/api/os/system.html#system-log in future for “debugging” on a productive system. Reliable, fast, and without noticeable overhead for the end-users.

1 Like