B4J Question webapp : jetty how to use setMaxTextMessageSize

Status
Not open for further replies.

billzhan

Active Member
Licensed User
Longtime User
Yes, about 115kb(and maybe more). It's the data of a spreadsheet which can be edited in web page.

Another solution : the data can be sent by ajax to server and be saved, the ws event will be called after ajax success event.

I prefer to make it in the ws thread.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
I actually think that it is better to use a servlet to upload the data.

However try this code:
B4X:
Sub SetMaxTextMessage(size As Int)
   Dim jo As JavaObject = ws
   jo = jo.GetFieldJO("session").RunMethod("getPolicy", Null)
   jo.RunMethod("setMaxTextMessageSize", Array(size))
End Sub

Call SetMaxTextMessage(1024 * 1024) in WebSocket_Connected sub. The code will update the internal limit (note that I haven't tested whether it actually increased the limit or not).
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User

This code works; the change is accepted but anyway the server will accept max 128KB or it raises an exception and the websocket will be disconnected.
 
Upvote 0

JackKirk

Well-Known Member
Licensed User
Longtime User
I tried this in an ABMaterial exercise I am playing with, my code is:
B4X:
Private Sub WebSocket_Connected (WebSocket1 As WebSocket)
    'Log("Connected")       
    ws = WebSocket1   
    
    Private wssize As Int = 128000
    Dim jo As JavaObject = ws
    jo = jo.GetFieldJO("session").RunMethod("getPolicy", Null)
    jo.RunMethod("setMaxTextMessageSize", Array(wssize))                  '<<<<<<<<<<<<<< line 40
    
    ABMPageId = ABM.GetPageID(Page, Name,ws)
    
    Main.Server.Connected(Me, ws, Page, ABMPageId)
    
    'Log(ABMPageId)
    Log("Connected: " & ABMPageId)
End Sub
But it bombs with:
Any suggestions appreciated...
 
Upvote 0

JackKirk

Well-Known Member
Licensed User
Longtime User
Grrrrr...

I just googled "java.lang.RuntimeException: Method: setMaxTextMessageSize not matched." and found this thread by Alain:

https://www.b4x.com/android/forum/threads/problems-with-jserver4-and-jetty11.141661/post-897938

the solution is:

B4X:
Private Sub WebSocket_Connected (WebSocket1 As WebSocket)
    'Log("Connected")       
    ws = WebSocket1   
    
    Private wssize As Long = 128000
    Dim jo As JavaObject = ws
    jo = jo.GetFieldJO("session").RunMethod("getPolicy", Null)
    jo.RunMethod("setMaxTextMessageSize", Array(wssize))
    
    ABMPageId = ABM.GetPageID(Page, Name,ws)
    
    Main.Server.Connected(Me, ws, Page, ABMPageId)
    
    'Log(ABMPageId)
    Log("Connected: " & ABMPageId)
End Sub
And the magic sauce is:

Private wssize As Long = 128000

NOT

Private wssize As Int = 128000
 
Upvote 0
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…