B4J Question [SOLVED] ws.Session.HasAttribute("name") and ws.Session.GetAttribute("name") does not work (Chatroom Example)

Martin Fdez

Member
Licensed User
Longtime User
Hi,
I'm testing the Chatroom example from Erel, the webapp works fine in Windows browser, Android browser, but when I tried to connect with an Iphone browser (Safari and Chrome) I set the username but when the Chat Page loads returns to Login Page.

That's because the ws.Session.HasAttribute("name") returns False and ws.Session.GetAttribute("name") returns Null

Anybody knows why and how to fix it?

Thank you all !!

Link to the Chatroom example: https://www.b4x.com/android/forum/t...ads-sessions-and-server-events.39969/#content

Here is the original code in the example that lost the session attributes in iphone browsers :

Chatroom example:
Private Sub WebSocket_Connected (WebSocket1 As WebSocket)
    ws = WebSocket1
If ws.Session.HasAttribute("name") = False Then
    'name not found. Go to the login page. This will happen if the user goes to the chat page directly.
    WebUtils.RedirectTo(ws, "index.html")
Else
    name = ws.Session.GetAttribute("name")
    ws.Session.RemoveAttribute("name") 'remove the attribute
    'the user will be redirected to the login page next time.
   
    CallSubDelayed3(ChatShared, "NewConnection", Me, name)
    txt.RunMethod("select", Null)
End If
End Sub
 
Last edited:

EnriqueGonzalez

Well-Known Member
Licensed User
Longtime User
Check if your example has this code
 
Upvote 0

Martin Fdez

Member
Licensed User
Longtime User
It works like a charm.

Thank you!!!
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…