Hello all there,
I am writing an app, in which a small feature should be to take Pictures and send them to a PC.
This Little Feature does not work correctly at a point, which i don't understand why it does not work.
Opening the Connection
Well, I make the photo and get the correct data from it. I send the length of the data to the Computer, which receives it correctly.
Afterwards, i send packages of data to the Computer.
After each package the PC receives, it sends an acknowledge, so the next package will be sent.
I know that this is still no perfect solution, because the Chance is very low that the file is exactly x*1000 Bytes, but that shall not matter for the moment.
2 times it works fine. But if the tablet sends the third package, the Computer just receives round about 1990 of the 2000 Bytes. The absolut amount of Bytes is not constant.
On the PC there is a Server written in VB, which reads Byte for Byte. Something like this
If the PC gets only 1990 Bytes, the while Loop does not end and the Programm gets stuck because it waits for data.
Well, I think this simply is not allowed to happen, because TCP guarantees a complete Transmission.
If I reduce the size of the packages to 5 Bytes, I can send round about 27 packages, but then I get the same Problem.
Neither B4A nor VisualStudio throws an exception, error or something like that.
I tried it with "Write" instead of "Write2", same Problem.
Could you give me a hint, where I have to search the Problem?
I am writing an app, in which a small feature should be to take Pictures and send them to a PC.
This Little Feature does not work correctly at a point, which i don't understand why it does not work.
Opening the Connection
B4X:
Dim socket1 As Socket
Dim AStreams As AsyncStreams
'In some Sub
socket1.Initialize("Socket1")
socket1.Connect("192.168.43.180", 4097, 5000)
B4X:
Sub Camera1_PictureTaken(Data() As Byte)
dataFile=DataDim out As OutputStream
out=File.OpenOutput(File.DirDefaultExternal, "42.jpg", False)
out.WriteBytes(Data, 0, Data.Length)
out.CloseToastMessageShow("Image saved: " & File.Combine(File.DirDefaultExternal, "42.jpg"), True)Dim datalength(4) As Byte
datalength(0)=(Data.Length/256/256/256)
datalength(1)=(Data.Length/256/256)
datalength(2)=(Data.Length/256)
datalength(3)=Data.Length
AStreams.Write2(datalength, 0, datalength.Length)
i = 0
camera1.StopPreview
End Sub
B4X:
Sub sendnextData()
j=0
Do While j < 2000
sendData(j)=dataFile(i)
j=j+1
i=i+1
Loop
AStreams.Write2(sendData, 0, sendData.Length)
End Sub
After each package the PC receives, it sends an acknowledge, so the next package will be sent.
B4X:
Sub AStreams_NewData(Buffer() As Byte)
If(Buffer(0)=75) Then
If i < dataFile.Length Then
sendnextData
Else
socket1.Close
End If
End If
End Sub
I know that this is still no perfect solution, because the Chance is very low that the file is exactly x*1000 Bytes, but that shall not matter for the moment.
2 times it works fine. But if the tablet sends the third package, the Computer just receives round about 1990 of the 2000 Bytes. The absolut amount of Bytes is not constant.
On the PC there is a Server written in VB, which reads Byte for Byte. Something like this
B4X:
Counter=0
while Counter< datasize
j=0
while j< 2000
FileAsByte(j)=Streamr.Read()
'save the data to file
j=j+1
Counter=Counter+1
end while
sendAcknowledge()
end while
Well, I think this simply is not allowed to happen, because TCP guarantees a complete Transmission.
If I reduce the size of the packages to 5 Bytes, I can send round about 27 packages, but then I get the same Problem.
Neither B4A nor VisualStudio throws an exception, error or something like that.
I tried it with "Write" instead of "Write2", same Problem.
Could you give me a hint, where I have to search the Problem?
Last edited: