B4J Question Message Too Large Exception

luisg2401

Member
Licensed User
Hello, I have a problem with the folowing code:

B4X:
    Dim script As String = $"
                            var video = document.getElementById('video');
                            var canvas = document.getElementById('canvas');
                            var context = canvas.getContext('2d');
                            var img = document.getElementById('image');
                          
                            canvas.width = video.clientWidth;
                            canvas.height = video.clientHeight;
                            context.drawImage(video, 0, 0);
                          
                            img.src = canvas.toDataURL();
                          
                            var aux = window.localStream;
                            aux.getTracks()[0].stop();
                            video.pause();
                            video.src = "";
                          
                            return img.src
    "$
    Dim res As Future = page.ws.EvalWithResult(script,Null)
    page.ws.Flush
    Log(res.Value)

this code gives me the following error:

B4X:
org.eclipse.jetty.websocket.api.MessageTooLargeException: Text message size [77072] exceeds maximum size [65536]

I already tried the solutions posted in these other threads:

https://www.b4x.com/android/forum/threads/websocket-received-data-exceeds-limit.90678/#content

I tried both of the solutions posted in that thread this way:

B4X:
Private Sub WebSocket_Connected (WebSocket1 As WebSocket)
    Dim ws1 As WebSocketClient
    ws1.Initialize("ws")
    Dim jo As JavaObject = ws1
    jo = jo.GetField("wsc")
    jo = jo.RunMethod("getPolicy", Null)
    jo = jo.RunMethod("setMaxTextMessageSize", Array As Object (128000))
...

only to end up with the same error

https://www.b4x.com/android/forum/threads/sending-binary-data-over-websocket.44776/#post-274162

I tried the solution posted on that thread this way:

B4X:
Private Sub WebSocket_Connected (WebSocket1 As WebSocket)
    Dim jo As JavaObject = WebSocket1
    jo = jo.GetField("options") 'WebSocketOptions
    jo.RunMethod("setMaxMessagePayloadSize", Array(4 * 1024 * 1024)) '4mb
...

and it gives me this error:

B4X:
java.lang.RuntimeException: Field: options not found in: anywheresoftware.b4j.object.WebSocket

am I doing something wrong with these solutions? Or is there something else I can do to fix that message too large error?
 
Last edited:

OliverA

Expert
Licensed User
Longtime User
https://www.b4x.com/android/forum/t...eb-server-setting-snippets.72625/#post-461800

Call this sub in WebSocket_Connected method after the
B4X:
ws = WebSocket1
line. I'm assuming you are using a WebSocket class template created from the IDE:
B4X:
'WebSocket class
Sub Class_Globals
   Private ws As WebSocket
End Sub

Public Sub Initialize
   
End Sub

Private Sub WebSocket_Connected (WebSocket1 As WebSocket)
   ws = WebSocket1
End Sub

Private Sub WebSocket_Disconnected

End Sub
 
Upvote 0

luisg2401

Member
Licensed User
https://www.b4x.com/android/forum/t...eb-server-setting-snippets.72625/#post-461800

Call this sub in WebSocket_Connected method after the
B4X:
ws = WebSocket1
line. I'm assuming you are using a WebSocket class template created from the IDE:
B4X:
'WebSocket class
Sub Class_Globals
   Private ws As WebSocket
End Sub

Public Sub Initialize
  
End Sub

Private Sub WebSocket_Connected (WebSocket1 As WebSocket)
   ws = WebSocket1
End Sub

Private Sub WebSocket_Disconnected

End Sub

Thanks, a lot! That solved my error, but now I get a different one when I try to get the value:

B4X:
java.util.concurrent.TimeoutException

what could be causing this error?
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
Upvote 0
Top