var aFs : TFileStream
....
..
///
/// demo server empfängt einen stream und sendet einen stream zurück
///
procedure TStreamServerForm.IdTCPServer1Execute(AContext: TIdContext);
var
LSize: LongInt;
begin
Memo1.Lines.Add('
Server starting .... ' );
AContext.Connection.IOHandler.ReadTimeout := 9000;
if ( ReceiveStream(AContext, TStream(afs)) = False )
then
begin
TIdNotify.NotifyMethod(ShowCannotGetStreamErrorMessage);
Exit;
end;
TIdNotify.NotifyMethod(StreamReceived);
if ( SendStream(AContext,TStream(afS)) = False )
then
begin
TIdNotify.NotifyMethod(ShowCannotSendStreamrErrorMessage);
Exit;
end;
Memo1.Lines.Add('
Server done .... ' );
end;
///
/// demo client schickt einen stream und einen bekommt einen anderen zurück ///
///
procedure TStreamExchangeClientForm.Button_SendStreamClick(Sender: TObject);
var LSize: LongInt;
begin
LSize := 0;
Memo1.Lines.Add('
Try send stream to server.....');
if (SendSTream(IdTCPClient1, TStream(afs)) = False)
then
begin
Memo1.Lines.Add('
Cannot send stream/buffer to server.');
Exit;
end;
if (ReceiveStream(IdTCPClient1, TStream(afs)) = False)
then
begin
Memo1.Lines.Add('
Cannot get "OK" message from server, Unknown error occured');
Exit;
end;
image1.Picture.Bitmap.LoadFromStream(afs);
end;
-----------------------------------------------------------------------------
die low level
indy routinen .....
------------------------------------------------------------------------------
function SendStream(AContext: TIdContext; AStream: TStream): Boolean;
overload;
begin
Result := False;
try
AContext.Connection.IOHandler.
Write(LongInt(SizeOf(AStream)));
AContext.Connection.IOHandler.WriteBufferOpen;
AContext.Connection.IOHandler.
Write(AStream, SizeOf(AStream));
AContext.Connection.IOHandler.WriteBufferFlush;
finally
AContext.Connection.IOHandler.WriteBufferClose;
end;
Result := True;
end;
function ReceiveStream(AContext: TIdContext;
var AStream: TStream):
Boolean;
overload;
var
LSize: LongInt;
begin
Result := False;
LSize := AContext.Connection.IOHandler.ReadLongInt();
AContext.Connection.IOHandler.ReadStream(AStream, LSize, False);
Result := True;
end;
function ReceiveStream(AClient: TIdTCPClient;
var AStream: TStream):
Boolean;
overload;
var
LSize: LongInt;
begin
Result := False;
LSize := AClient.IOHandler.ReadLongInt();
AClient.IOHandler.ReadStream(AStream, LSize, False);
Result := True;
end;
function SendStream(AClient: TIdTCPClient; AStream: TStream): Boolean;
overload;
var StreamSize : LongInt;
begin
Result := True;
try
StreamSize := (AStream.Size);
AStream.Seek(0, soFromBeginning);
AClient.IOHandler.LargeStream := True;
AClient.IOHandler.SendBufferSize := 32768;
AClient.IOHandler.
Write(LongInt(StreamSize));
AClient.IOHandler.WriteBufferOpen;
AClient.IOHandler.
Write(AStream, LongInt(StreamSize));
AClient.IOHandler.WriteBufferFlush;
finally
AClient.IOHandler.WriteBufferClose;
end;
Result := True;
end;