B4J Question Websocket crash in release mode

techknight

Well-Known Member
Licensed User
Longtime User
I am having an issue on a UI App that has a websocket server.

In debug mode, everything works perfectly fine.

But if I switch it to release/Release obfuscating mode, Soon as I attempt to connect via websocket, it crashes and boots the websocket connection instantly with this error:

B4X:
2018-07-20 09:01:54.315:INFO:oejs.Server:JavaFX Application Thread: Started @1481ms
Server started
java.lang.RuntimeException: not supported
    at anywheresoftware.b4j.objects.FxBA.cleanMessageLoop(FxBA.java:37)
    at anywheresoftware.b4j.object.WebSocketModule$Adapter$ThreadHandler.run(WebSocketModule.java:182)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:748)

Since I have no idea whats triggering this issue, I am unsure how to fix it.
 

techknight

Well-Known Member
Licensed User
Longtime User
I discovered Jserver is buggy with UI apps. So I had to split the program apart into two halves. the server half, and UI half. Kludgy in my opinion but I guess it is what it is.
 
Upvote 0

Blueforcer

Well-Known Member
Licensed User
Longtime User
Same here,
I only noticed this after my program was finished and I started the program in release mode
But with another error:
B4X:
java.lang.NoSuchMethodException: b4j.example.remote.innerInitializeHelper(anywheresoftware.b4a.BA)

A normal Webserver Handler works for my REST API, btw

Unfortunately, this documentationdoesn't say anything about
https://www.b4x.com/b4j/help/jserver.html#server
Also the Websocket Tutorial says nothing about it.
Only in the web server tutorial i found one line:
"A server program is a non-UI program."

But no matter, because I want to stream my Form to a website, I have to run a second non-GUI application at the same time. No Porblem for now i think.

But just out of interest I would also like to know why it works in debug mode but not in the release. How it works? I thought debug just compile some logging code into.
Couldn't there be a trick to simulate the server in debug mode?
 
Upvote 0

EnriqueGonzalez

Well-Known Member
Licensed User
Longtime User
The way ui projects handles threads is very different from which the jserver does. It works in debug mode because in debug everything incluiding the ui runs on the same thread. That is something you don't want on jserver.
 
Upvote 0

techknight

Well-Known Member
Licensed User
Longtime User
So in order for this to ever work, we would need a jServerFX. I had a feeling something was up when the Create Websocket Class was missing from the list of options for the UI app.

Anyways, I ended up ditching Websockets in favor of MQTT because the problem with Websockets is lag time.

For example if I have 10 clients connected, and I am sending data through a For Each loop, it could be a second or two before it reaches the end, and anything that is timing related now gets blown out of the water.

I was not sure if it was even possible to "broadcast" to all clients at the same time on Websockets, so I went to MQTT.

That worked MUCH better and it is compatible with UI apps.

In my case I wasnt using any web pages. I was trying to connect multiple apps together at the server, at the same time. When the server clock ticks, all the clients tick at the beat of the server.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…