B4J Question Using Jserver 4 and websockets WSS

Swissmade

Well-Known Member
Licensed User
Longtime User
I have build a Websocket Server with SSL. Cloudflare cert.
Working perfect but now I wondering how to use WSS instate WS.
The server uses this.
I forgot about WSS until I have seen somebody has download my website.
Server Init:
        srvr.AddFilter("/b4j_ws.js", "SessionCreator", False)
        srvr.AddWebSocket("/ws", "JamulusAudioweb")

'        srvr.AddHandler("/*", "classClientServer", False)

        modFunctions.LogText("Server Start at Server IP " & ServerIP, True)
        Port = 80 '8080 '8880  51042
        srvr.Port = Port
        sslPort = 443
        If SSLUsed = True Then
            ConfigureSSL(sslPort)
        End If
        srvr.DebugNetworkLatency = 200
ConfigureSSL:
Private Sub ConfigureSSL(sslPortUsed As Int)
    Try
        Dim ssl As SslConfiguration
        ssl.Initialize
        ssl.SetKeyStorePath(File.DirApp, "keystore.jks")
        ssl.KeyStorePassword = <PWStore>
        ssl.KeyManagerPassword = <PWmanager>
        ' Add detailed logging
        modFunctions.LogText("Keystore path: " & File.DirApp & "/keystore.jks", True)
        modFunctions.LogText("Using SSL port: " & sslPortUsed, True)
'        Log("Keystore password length: " & ssl.KeyStorePassword.Length)
        
        ' Add detailed logging
        modFunctions.LogText("Using SSL port: " & sslPortUsed, True)
        
        srvr.SetSslConfiguration(ssl, sslPort)
    Catch
        modFunctions.LogText("Error configuring SSL: " & LastException.Message, True)
    End Try
    'Optional: Add filter to redirect HTTP to HTTPS
End Sub
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
I forgot about WSS until I have seen somebody has download my website.
WSS will not prevent anyone from downloading your content. It will make them download it over a secure connection.

Your code looks correct. b4j_ws.js will set the scheme to wss when the current protocol is https.
 
Upvote 0

Swissmade

Well-Known Member
Licensed User
Longtime User
WSS will not prevent anyone from downloading your content. It will make them download it over a secure connection.

Your code looks correct. b4j_ws.js will set the scheme to wss when the current protocol is https.
Top thanks Erel
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…