Delphi Mobile App Send Image Through Tidtcpclient (Connection Closed Gracefully)

  

I am using Delphi 10.2 and build a mobile app
one of my tasks to send images from mobile to a server
I get a code from stackoverflow to do this and run it but it is not working

server side code on execute

type
TSendRec = record
SONo: string;
Text: string;
Bitmap: TBitmap;
end;

procedure TForm1.IdTCPServer1Execute(AContext: TIdContext);
var
MIRec: TSendRec;
ms: TMemoryStream;
begin
try
MIRec.SONo := AContext.Connection.IOHandler.ReadLn;
MIRec.Text := AContext.Connection.IOHandler.ReadLn;
MIRec.Bitmap := TBitmap.Create;

ms := TMemoryStream.Create;
try
AContext.Connection.IOHandler.LargeStream := True;
AContext.Connection.IOHandler.ReadStream(ms, -1, False);
ms.Position := 0;
MIRec.Bitmap.LoadFromStream(ms);
finally
ms.Free;
end;
TThread.Synchronize(nil,
procedure
begin
Memo1.Lines.Add(MIRec.SONo);
Memo1.Lines.Add(MIRec.Text);
MIRec.Bitmap.SaveToFile(‘C:\To Receive\test.bmp’);
end
);
finally
MIRec.Bitmap.Free;
end;
end;

and Client code is

procedure TForm2.Button2Click(Sender: TObject);
var
MIRec: TSendRec;
ms: TMemoryStream;
begin
MIRec.SONo := IntToStr(Ticket_ID);
MIRec.Text := ‘Pic_’+IntToStr(Ticket_ID);
MIRec.Bitmap := TBitmap.Create;
MIRec.Bitmap.Assign(imgPhotoLibraryImage.Bitmap);
try
IdTCPClient1.Connect;
try
IdTCPClient1.IOHandler.WriteLn(MIRec.SONo);
IdTCPClient1.IOHandler.WriteLn(MIRec.Text);
ms := TMemoryStream.Create;
try
MIRec.Bitmap.SaveToStream(ms);
IdTCPClient1.IOHandler.LargeStream := True;
IdTCPClient1.IOHandler.Write(ms, 0, True);
ShowMessage(‘Image Uploaded’);
imgPhotoLibraryImage.Bitmap.Assign(nil);
finally
ms.Free;
end;
finally
IdTCPClient1.Disconnect;
end;
finally
MIRec.Bitmap.Free;
end;
end;

now in the server side I get an error Connection closed gracefully

any help plz

Comments are closed.