Android Question Send imag from b4a to delphi application

invocker

Active Member
Hi

when I try To send A small image less then 6 k over socket It's Ok but In big image I Received a corrupted file How can Resolve it ?

b4a code
Code:
If Successful Then
             astream.Initialize(socket.InputStream,socket.OutputStream,"astream")
            ' astream.InitializePrefix(socket.InputStream,True,socket.OutputStream,"astream")
         End If

Private Sub astream_NewData (Buffer() As Byte)
If File.Exists(File.DirRootExternal, "Pictures/1.jpg") Then
                Dim Data() As Byte=Bit.InputStreamToBytes(File.OpenInput(File.DirRootExternal, "Pictures/1.jpg")) ' jpg 156 Ko
                If  astream.Write(Data) Then
                     Log(Data.Length)
                End If
                Else
                Log("File Not Found")
            End If
End Sub
delphi code

Code:
procedure TForm1.serverClientRead(Sender: TObject; Socket: TCustomWinSocket);
var
  Stream: TStringStream;
      begin
        Stream := TStringStream.Create;
        try
          Stream.Position := 0;
          Stream.WriteString(Socket.ReceiveText);
          Stream.SaveToFile('D:\Received.jpg'); //jpg Received  6,66 Ko
        finally
          Stream.Free;
        end;
end;
 
Last edited:
in b4j it work perfect and receive image completly by use InitializePrefix in both b4a and b4j but I can't use InitializePrefix with delphi
 
Upvote 0
You will need to either switch to B4J, and then everything will be simple, or fix the delphi code to collect all the data and only then write it.
Also make sure not to read the data on the main thread in your delphi code. Otherwise your app will freeze until all data is received.
 
Upvote 0
Back
Top