Android Question Websocket communication - windows problem?

rosippc64a

Active Member
Licensed User
Longtime User
Hi All!
Months ago I made a program that connect an android application to a B4J program via web socket. Since I registered for duckdns, this connection worked remotely also. Although I didn't have to use it, it started automatically on the pc every day. The B4J program has a status page that can be opened in a browser to query the log data.
Today I tried again to see whether the program works and was surprised to find that although the B4J program is running and the log can be viewed in a browser both on the PC and android too (http://192.168.0.155:54021/stat - no errors), the websocket communication (ws://192.168.0.155:54021/ws) no longer works within the local network either. No connection between android and PC. If I turn off windows defender and firewall, no connection either. Something is blocking websocket communication, but I have no idea where to look in Windows10? Can someone help me?
thanks in advance
Steven
 
Last edited:

rosippc64a

Active Member
Licensed User
Longtime User
I found the error, but I miss the full understanding.
Here is a line in configuressl sub:
srvr.AddFilter("/*", "HttpsFilter", False):
srvr.AddFilter("/*", "HttpsFilter", False)
My httpsfilter looks like (as in sample program):
B4X:
'Return True to allow the request to proceed.
Public Sub Filter(req As ServletRequest, resp As ServletResponse) As Boolean
    If req.Secure Then       
        Return True
    Else
        resp.SendRedirect(req.FullRequestURI.Replace("http:", "https:").Replace(Main.srvr.Port, Main.srvr.SslPort))
        Return False
    End If
End Sub
That is good for my http://... and https://... , but that prevented my ws connection by redirecting to a wrong way.
I modified to this:
B4X:
'Return True to allow the request to proceed.
Public Sub Filter(req As ServletRequest, resp As ServletResponse) As Boolean
    If req.Secure Or req.RequestURI="/ws" Then       
        Return True
    Else
        resp.SendRedirect(req.FullRequestURI.Replace("http:", "https:").Replace(Main.srvr.Port, Main.srvr.SslPort))
        Return False
    End If
End Sub
so actually my ws connection works.
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
ws uses http and wss uses https
Since you were redirecting all http traffic to https, you were breaking ws (ws does not automatically switch to wss). Now, if you made no code changes, it does seem a little bit mysterious that you are running into this issue just now.
 
Upvote 1

rosippc64a

Active Member
Licensed User
Longtime User
Yes, sure, seem a little bit mysterious.
As I wrote, I hadn't had to use it before and I guess first I had to get the websocket working correctly and then insert https but then I was confident that ws would work...

By the way my duckdns isn't work yet, so I have to set something somewhere. I checked already the router port forwarding for incoming traffic, the windows firewall for my app and used port too, but not yet result.
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
Http is port 80 and https is port 443, unless you reconfigured the ports.

Look at your log files (of your B4J app) and make sure there are no error messages regarding https connections
Make sure windows is not blocking the https port
Make sure the router is not blocking the https port
Worst case scenario, your ISP is blocking incoming https requests.
It would help if you can see a log of incoming traffic on your router, this way you at least could determine if you are getting the traffic
 
Upvote 0

rosippc64a

Active Member
Licensed User
Longtime User
I have reconfigured ports and I have problem http incoming traffic also. I checked port forwarding in the router and port enabling in firewall + defender. In the server log there is no error - because I think there is no incoming data at all. :-(
 
Upvote 0
Top