No, the file does not arrive correctly. As far as I can trace , the error occurs in AsyncStreamsText.bas in
Private Sub astream_NewStream (Dir As String, FileName As String) on line :
waitingForKey = raf.ReadB4XObject(raf.CurrentPosition)
Before waitingForKey I have logged raf.size. Result: 46, whereas the image size is reported to be 88,099 by the server, just before .WriteFile
Using AsyncStreamsObject I have the following code:
Dim Stream2 As AsyncStreamsObject
Dim Client2 As Socket
Client2.Initialize("Client2")
If wifi.IsWifiConnected= True AND wifi.getSSID="JetStream" Then
Local=True
Client2.Connect("192.168.2.5",8400, 20000)
Else
Local=False
Client2.Connect("my ip addr",8400,20000)
End If
Sub Client2_Connected (Successful As Boolean)
If Successful Then
If Stream2.IsInitialized =True Then
Stream2.Close
End If
Stream2.Initialize(Me,"Stream2")
Stream2.Start(Client2.InputStream,Client2.OutputStream)
Send(Mode) 'instruction to the server via other stream to read webcam
Else
ToastMessageShow(LastException.Message, True)
End If
End Sub
Sub Stream2_NewObject(Key As String, Value As Object)
If Key="Webcam" Then
Dim filename As String = Value
If File.Exists("/storage/extSdCard/Domotica","camview.jpg") Then
File.Delete("/storage/extSdCard/Domotica","camview.jpg")
End If
File.Copy(Stream2.TempFolder,filename, "/storage/extSdCard/Domotica", "camview.jpg")
End If
End Sub
The NewObject sub is never activated; the program aborts before.
The program uses another stream as AsyncStreamsText, to exchange text data with the sever; that works great.
During latest test after the error message mentionned before; following log appeared:
"sending message to waiting queue (astream_newstream)"
"running waiting messages (1)"
After a while the program continued and the correct file length was shown; my log.
Then the message:
"java.lang.NegativeArraySizeException: -2555937"
I hope you can find something.
Harry