Hello.
I' using ASyncStreams to send files to and from Android devices and computers. It is quite simple to use and I'm very happy about it.
Unfortunately there is an issue... Whenever I try to send files of about 200 kb and above over bluetooth, the receiving B4J app crashes, with following output:
It works fine with Wifi connection.
Line 219, referred as the one that caused the crash reads:
This line is inside this routine:
fs is a Type from this Tutorial about ASyncStreams + B4XSerializator that reads:
On the B4A side, the code is:
In 'Transferer' Service:
On the 'Transfere_Dados' Activity, the code is:
Why it does not work with Bluetooth?
Any ideas or workarounds?
I' using ASyncStreams to send files to and from Android devices and computers. It is quite simple to use and I'm very happy about it.
Unfortunately there is an issue... Whenever I try to send files of about 200 kb and above over bluetooth, the receiving B4J app crashes, with following output:
B4X:
java.lang.RuntimeException: Message size too large. Prefix mode can only work if both sides of the connection follow the 'prefix' protocol.
at anywheresoftware.b4a.randomaccessfile.AsyncStreams$AIN.run(AsyncStreams.java:205)
at java.lang.Thread.run(Thread.java:745)
Error occurred on line: 219
java.lang.RuntimeException: java.util.zip.ZipException: invalid distance too far back
at anywheresoftware.b4a.randomaccessfile.B4XSerializator.readType(B4XSerializator.java:295)
at anywheresoftware.b4a.randomaccessfile.B4XSerializator.readObject(B4XSerializator.java:355)
at anywheresoftware.b4a.randomaccessfile.B4XSerializator.ReadObject(B4XSerializator.java:110)
at anywheresoftware.b4a.randomaccessfile.B4XSerializator.ConvertBytesToObject(B4XSerializator.java:81)
at sun.reflect.GeneratedMethodAccessor11.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:612)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:226)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:159)
at sun.reflect.GeneratedMethodAccessor3.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:93)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:90)
at anywheresoftware.b4a.debug.Debug.delegate(Debug.java:61)
at lbmdata.zepi.main._processa_sync(main.java:350)
at lbmdata.zepi.main._astream_newdata(main.java:333)
at sun.reflect.GeneratedMethodAccessor5.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:612)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:229)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:159)
at sun.reflect.GeneratedMethodAccessor3.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:93)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:90)
at anywheresoftware.b4a.BA$3.run(BA.java:178)
at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.util.zip.ZipException: invalid distance too far back
at java.util.zip.InflaterInputStream.read(InflaterInputStream.java:164)
at java.io.DataInputStream.readFully(DataInputStream.java:195)
at java.io.DataInputStream.readFully(DataInputStream.java:169)
at anywheresoftware.b4a.randomaccessfile.B4XSerializator.readObject(B4XSerializator.java:349)
at anywheresoftware.b4a.randomaccessfile.B4XSerializator.readMap(B4XSerializator.java:229)
at anywheresoftware.b4a.randomaccessfile.B4XSerializator.readType(B4XSerializator.java:273)
... 36 more
It works fine with Wifi connection.
Line 219, referred as the one that caused the crash reads:
B4X:
fs = ser.ConvertBytesToObject(Buffer)
This line is inside this routine:
B4X:
Sub Processa_Sync(Buffer() As Byte)
fs = ser.ConvertBytesToObject(Buffer)
If fs.FileName = "Recebido" Then
Log("Received all files")
End If
out = File.OpenOutput(File.DirData("lbmdata\zEPI\Temp"), fs.FileName, False)
out.WriteBytes(fs.Data, 0, fs.Data.Length)
out.Close
localfileparts = 0
txt_Eventos.Text = txt_Eventos.Text & "'" & fs.FileName & "' OK - " & NumberFormat2((Buffer.Length/1024),0,2,2,False) & " KB" & CRLF
End Sub
Sub astream_NewData (Buffer() As Byte)
Try
Processa_Sync(Buffer)
Catch
Log(LastException.Message)
fx.Msgbox(MainForm, "Erro: " & LastException.Message, "Exceção")
End Try
End Sub
fs is a Type from this Tutorial about ASyncStreams + B4XSerializator that reads:
B4X:
Type FileToSend(FileName As String, Data() As Byte)
On the B4A side, the code is:
In 'Transferer' Service:
B4X:
Sub Envia_Arquivo(Arquivo As String)
fs.Initialize
fs.FileName = Arquivo
Log(fs.FileName)
fs.Data = Bit.InputStreamToBytes(File.OpenInput(File.DirDefaultExternal, Arquivo))
bytes = ser.ConvertObjectToBytes(fs)
astream.Write(bytes)
End Sub
Sub astream_NewData (Buffer() As Byte)
CallSub2(Transfere_Dados, "NewData", Buffer)
End Sub
On the 'Transfere_Dados' Activity, the code is:
B4X:
Sub NewData (data() As Byte)
fs = Ser.ConvertBytesToObject(data)
Dim out As OutputStream = File.OpenOutput(File.DirDefaultExternal, fs.FileName, False)
out.WriteBytes(fs.Data, 0, fs.Data.Length)
out.Close
If contador = 3 Then
Dim ft As FileToSend
Dim bb() As Byte
'Signals reception to B4J
ft.Initialize
ft.FileName = "Recebido"
ft.Data = Bit.InputStreamToBytes(File.OpenInput(File.DirDefaultExternal, "Semente.jsn"))
bb = Ser.ConvertObjectToBytes(ft)
Transferer.astream.Write(bb)
Activity.Finish
End If
End Sub
Why it does not work with Bluetooth?
Any ideas or workarounds?