Android Question problem connecting to server using websocket client

coddy

Member
i have downloaded the example in this tutorial and i want to connect it to my server for test.
the web socket i'm using works fine and for connection it needs user name and password.
B4X:
Sub Process_Globals
    Private wsh As WebSocketHandler
    Private link As String = "ws://5*.3*.126.245:37*1/ws"
End Sub
this is the way to set ip and port but how set user name and password for connection
 

drgottjr

Expert
Licensed User
Longtime User
see if the last post here helps. you send your credentials in the header
 
Upvote 0

coddy

Member
B4X:
Sub Globals
    Private cred As String
    Dim su As StringUtils
    Dim encoded As String
    Dim mp As Map
End Sub

Sub Activity_Create(FirstTime As Boolean)
    cred = "****rto:****BAR2210"
    lst.Initialize
    encoded = su.EncodeBase64(cred.GetBytes("UTF8"))
    If FirstTime Then
        wsh.Initialize(Me)
    End If
    Activity.LoadLayout("1")
    mp = CreateMap("Authorization":"Basic "&encoded)
    wsh.Headers(mp)
End Sub
i don't know what's wrong with the header.
Untitled-1.png
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
you've got it a little backwards:
B4X:
ws.Headers = CreateMap("Authorization":"Basic "&encoded)
ws.Connect(Url)
 
Upvote 0
Top