B4J Question SOLVED - [ABMaterial] WebSocket timeout

Harris

Expert
Licensed User
Longtime User
b4j_ws.min.js:1 connection is closed. Trying to reconnect.

I keep getting the above from my remote server. Using Chrome browser on my Win 8.1 PC.
(This also happens on my dev laptop with local server).

The site is: http://104.168.173.164:51050/punchclock/
(demo / demo) - user and password

Menu - Configure App, any sub item - Company, Users, Employees....
When the table does not populate (Employees), you can click the pagination arrow and the grid will update but not fully (tool bar is missing in Row 1).
Pressing F5 repeatably is like rolling the dice - maybe you will get lucky.

Any Ideas?

I have implemented the re-connect websocket code as per advised:

B4X:
' class_globals...
    Type GuessMyNumberState (Number As Int)
    Private state As GuessMyNumberState

' sub...
Private Sub WebSocket_Connected (WebSocket1 As WebSocket)
    Log("Emp Connected")
    ws = WebSocket1   
   
   Dim session As HttpSession = ws.UpgradeRequest.GetSession
   If session.HasAttribute("state") = False Then
     state.Initialize
     state.Number = Rnd(1, 101)
     session.SetAttribute("state", state) 'sets a reference to the state object.
     Log($"Creating new state. Number = ${state.Number}"$)
   Else
     state = session.GetAttribute("state")
     Log($"Reusing previous state. Number = ${state.Number}"$)
   End If
  
    If ABMShared.NeedsAuthorization Then
        Log(" Needs Autho ")
        If ws.Session.GetAttribute2("IsAuthorized", "") = "" Then
            Log(" Must Autho")
            ABMShared.NavigateToPage(ws, "../")
            Return
        End If
    End If
    ' connect our page with the websocket   
    page.SetWebSocket(ws)
    Log(" page.SetWebSocket...")

    ' Prepare the page IMPORTANT!
    page.Prepare   
   
    UserType = page.ws.Session.GetAttribute2( "UserType", "0")
    UserID = page.ws.Session.GetAttribute2("UserID", "0")
    UserRows = page.ws.Session.GetAttribute2("UserRows", "0")
   
    Dim SQL As SQL = DBM.GetSQL
    Dim users As List = DBM.SQLSelect(SQL, "SELECT UserName, UserRows FROM Users WHERE userId=" & UserID)
    If users.Size > 0 Then
        Dim user As Map = users.Get(0)
        UserName = user.GetDefault("username", "")
        UserRows = user.GetDefault("userrows",  5)
        If UserRows > 0 Then
           iRecs = UserRows
        Else
           iRecs = 5
        End If 
    Log(" users.Size > 0...")           
    End If
       
    DBM.CloseSQL(SQL)
   
    page.NavigationBar.Refresh
    Log(" page.NavigationBar.Refresh... or not...")
End Sub
 

Harris

Expert
Licensed User
Longtime User
Clear as mud...

I shall work through it and report back when I have it ( or not ) working.

Seems simple enough, but I always have a time sorting what was "client" and what was "server" - (as do most).

If you ever get time, using my code, create a working example implementing what you have expressed.

That may clear it up. I don't know why I don't see this clearly?

Thanks
 
Upvote 0

alwaysbusy

Expert
Licensed User
Longtime User
@Harris Shut down your PC and go to bed, right now! Doctor's orders! :)

When you're re-reading my last post in the morning, it is going to by crystal, as you're doing this already exactly the same with e.g. ws.Session.SetAttribute("UserRows",...)

Note: just do not forget to set 'page.ws.Session.SetAttribute("UserAction", "Company")' in ABMApplication WebSocket_Connected() to set an initial value. (now you do this too with Public pgActionName As String = "Company")

Sweet dreams!
 
Upvote 0

Harris

Expert
Licensed User
Longtime User
@Harris Shut down your PC and go to bed, right now! Doctor's orders! :)

When you're re-reading my last post in the morning, it is going to by crystal, as you're doing this already exactly the same with e.g. ws.Session.SetAttribute("UserRows",...)

Note: just do not forget to set 'page.ws.Session.SetAttribute("UserAction", "Company")' in ABMApplication WebSocket_Connected() to set an initial value. (now you do this too with Public pgActionName As String = "Company")

Sweet dreams!

Good advice Doc!

I needed that. Brain was stuck in reverse with clutch slipping badly. Geeeezzzz...

I have it functioning now - as per your spec. Just one simple issue..

In ABMShared:
page.NavigationBar.Initialize(page, "nav1", ABM.SIDEBAR_MANUAL_ALWAYSHIDE, Title, True, True, 330, 48, sbtopimg, ABM.COLLAPSE_ACCORDION, "nav1theme")

This is is only place where the page Title is set ("Employees" , "Users", etc). Called on BuildPage (which can't have ws reference since not inited on app start)

When using the other browser, the Title is always set to what the last users was browsing (when pressing F5 to refresh).

Thanks
 
Upvote 0

Harris

Expert
Licensed User
Longtime User
Not related to above post...

When I disable my ESET firewall and internet protection, each page does NOT report "connection failed" (more often than not).

It updates each page fine - just like you were seeing during your tests since (I assume) you do not have ESET protection installed.

Hell, there is hope for my sanity yet!
 
Upvote 0

alwaysbusy

Expert
Licensed User
Longtime User
page.NavigationBar.Initialize(page, "nav1", ABM.SIDEBAR_MANUAL_ALWAYSHIDE, Title, True, True, 330, 48, sbtopimg, ABM.COLLAPSE_ACCORDION, "nav1theme")
This is exactly why my work on 1.09 is important. In 1.09 all components are dynamic, so you will be able to set the title in the connect rather than in the build. ETA is somewhere next week.

Hell, there is hope for my sanity yet!
I wouldn't go that far yet. Relapse is often seen in cases like yours :)
 
Upvote 0

Harris

Expert
Licensed User
Longtime User
I wouldn't go that far yet. Relapse is often seen in cases like yours :)

Humor my old ass.. God, to be 18 again...

(Build currently is limited in usefulness- lacks the dynamic, like you say.)

Seems you are always about to implement what I am frigging with.
My best play is to lay back and see what you come up with. But, how would you or I know unless we experienced the same (pushed to the limit) issue?

Good for me, but sucks for my clients - unless I inform them of development progress.

Also, sucks for me cause I can't get paid delivering on schedule (THIS is entirely MY problem - I choose MY Framework - that I trust).

However, I have trained them to wait for perfection, rather than deal with exception (ie. frustrate the hell out of them cause this S&$! don't work).

My goal is to create a stable framework for both mobile and server, where little mods will be required to apply to new clients.
This project shall establish that.
This is a huge task, but I have been around this block for 38+ years - the functional issues are minimal. The mobile issues are (somewhat) minimal, the server webapp issues are (currently) huge (cause I am need of your expertise) .

Thanks
 
Upvote 0
Top