B4J Question Why Doesn't This Websocket Connect?

cklester

Well-Known Member
Licensed User
I think this should connect. I've tested the URL with an online websocket connection tester, and the connection works there.

B4X:
Private Sub StartWebsocket
    wsc.Initialize("wsc")
    wsc.Connect("wss://ws-feed.exchange.coinbase.com")
    Wait For wsc_Connected
    Log("Websocket connected!")
End Sub

It never gets to the wsc_Connected event.

The websocket docs are here. I don't know what I'm missing...

Can anybody get this to work?
 

cklester

Well-Known Member
Licensed User
Might I have different modules than you?

Here's mine for a very simple B4XPages app (see attached) to test this:



And here's the error log I get:

 

Attachments

  • test-websocket-to-coinbase.zip
    8.7 KB · Views: 120
Upvote 0

cklester

Well-Known Member
Licensed User
Yours works too. Check your firewall(s).

Crazy thing is, I can connect to a different websocket from another provider.

This one requires you to get a connection token first, but it's generally all the same:

B4X:
Public Sub WebSocketConnect As ResumableSub
    wait for (Main.Shrimpy.GetWebsocketToken) complete(result As String)
    If result.Contains("SocketTimeoutException: timeout") Then
        Return False
    End If
    Private wst As String = result.As(JSON).ToMap.Get("token")
    Main.WebSocket.Initialize("ws")
    Dim wsurl As String = "wss://ws-feed.shrimpy.io?token=" & wst
    Main.WebSocket.Connect(wsurl)
    wait for ws_Connected
    Log("Websocket connected")
    Return True
End Sub

That works for me! I can also subscribe and start streaming data.
 
Upvote 0

cklester

Well-Known Member
Licensed User
if that is so, then your ip could be banned.

I can test the websocket from a browser, so I think that means my IP is not banned.

So now I'm stuck. I don't understand why I can connect via websocket to one site but not to these two others.

If anybody has any other clues or hints for me, please let me know. I will slowly be pulling my hair out in the meantime.
 
Upvote 0

cklester

Well-Known Member
Licensed User
Just got this to connect: wss://quadency.com/api/v1/public/ws in my sample app (above), but it's not working in my main app.

At least that's progress!
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…