blackhorse-one / stomp_dart_client

Dart STOMP client for easy messaging interoperability.
BSD 3-Clause "New" or "Revised" License
59 stars 44 forks source link

Stomp Dart Client Package Supports HTTPS/WSS Websocket Connection OR NOT #94

Closed SkyPrince77 closed 1 year ago

SkyPrince77 commented 1 year ago

i created websocket connection from my flutter app in mobile. it works fine when using http in sockJs constructor but after the server is upgraded to https i also change the url to https but it won't connect. is there is anything i need to send additionally to https connection when compare to the http

Screenshot 2023-10-17 111404

I NEED TO KNOW IS STOMP DART CLIENET PACKAGE SUPPORT HTTPS/WSS WEBSOCKET CONNECTION OR NOT

PLEASE HELP ME I WAS STUCK IN THIS PROBLEM MORE THAN A MONTH

KammererTob commented 1 year ago

Hi,

it should work with https, we use it ourself in production. Does it generate any errors, or what exactly is happening?

SkyPrince777 commented 1 year ago

Yes it generates this error "Url was not upgraded to websocket"

KammererTob commented 1 year ago

This error sounds like an issue on your server. The connection is normally upgraded to websocket on there. Are you sure that port 443 is correctly responding with the upgrade headers and handling the websocket connection?

SkyPrince77 commented 1 year ago

I think the issue might be occur in apache config file, but the same websocket connection in website(Angular) works properly. is there is anything specific i need to add i apache config file or made some changes according to the flutter websocket connection.

Can you guide me to configure apache config file properly according to the flutter websocket connection

KammererTob commented 1 year ago

Can you share your current apache config which deals with the websocket connection? And maybe also your client (Angular) code where you connect successfully? Normally there shouldn't be anything special required to connect from flutter.

SkyPrince777 commented 1 year ago

My issue Fixed, Issue not belongs to frontend side, above code is working perfectly. Error occurred in apache config file. I fixed that issue by adding this below rules to my apache config file Reference: <VirtualHost *:443>

    ServerName the.domain.tld
    ProxyPass / http://localhost:5001/
    ProxyPassReverse / http://localhost:5001/
    ProxyPass /api/socket http://localhost:5001/api/socket/
    ProxyPassReverse /api/socket http://localhost:5001/api/socket/

    RewriteEngine on

    RewriteCond %{HTTP:Upgrade} websocket [NC]
    RewriteCond %{HTTP:Connection} upgrade [NC]
    RewriteRule /(.*) "ws://localhost:5001/$1" [P,L]

    ProxyPreserveHost On
    ProxyAddHeaders On
    RequestHeader set X-Forwarded-Proto "https"

    SSLCertificateFile /path/to/tls/tls.crt
    SSLCertificateKeyFile /path/to/tls/tls.key

    SSLProxyEngine On

`

Ref: https://serverfault.com/questions/1078840/replicate-nginx-reverse-proxy-config-using-apache

Note: if anyone use the above code don't change the order of the rules

Thanks a lot for your great and quick support