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).
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).
Sub SetMaxTextMessage(size As Int)
Dim jo As JavaObject = ws
jo = jo.GetFieldJO("session").RunMethod("getPolicy", Null)
jo.RunMethod("setMaxTextMessageSize", Array(size))
End Sub
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:
Error occurred on line: 40 (CameraPage)
java.lang.RuntimeException: Method: setMaxTextMessageSize not matched.
at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:130)
at com.ab.template.camerapage._websocket_connected(camerapage.java:389)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:629)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:237)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)
at jdk.internal.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:111)
at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:100)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:98)
at anywheresoftware.b4j.object.WebSocketModule$Adapter$ThreadHandler.run(WebSocketModule.java:204)
at anywheresoftware.b4a.keywords.SimpleMessageLoop.runMessageLoop(SimpleMessageLoop.java:47)
at anywheresoftware.b4a.StandardBA.startMessageLoop(StandardBA.java:43)
at anywheresoftware.b4a.shell.ShellBA.startMessageLoop(ShellBA.java:121)
at anywheresoftware.b4a.keywords.Common.StartMessageLoop(Common.java:180)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:309)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:111)
at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:100)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:98)
at anywheresoftware.b4j.object.JServlet.createInstance(JServlet.java:81)
at anywheresoftware.b4j.object.BackgroundWorkersManager$1.run(BackgroundWorkersManager.java:40)
at anywheresoftware.b4a.keywords.SimpleMessageLoop.runMessageLoop(SimpleMessageLoop.java:47)
at anywheresoftware.b4a.StandardBA.startMessageLoop(StandardBA.java:43)
at anywheresoftware.b4a.shell.ShellBA.startMessageLoop(ShellBA.java:121)
at anywheresoftware.b4a.keywords.Common.StartMessageLoop(Common.java:180)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:309)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:111)
at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:100)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:98)
at com.ab.template.main.main(main.java:29)
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