Newsgroups : Borland : borland.public.delphi.internet.winsock : 2008 Jul : Read/Write Stream

www.cryer.info
Managed Newsgroup Archive

Read/Write Stream

Subject:Read/Write Stream
Posted by:"Eric W. Carman" (ewcarman@_removethis_ecsoftwareconsulitng.dot.com)
Date:Mon, 7 Jul 2008 16:52:59

I'm trying to communicate between an indy client and server using the
read/write stream methods and I'm missing something....

When I try this:

procedure TMyAppServer.IdTCPServer1Execute(AContext: TIdContext);
var
  BLArea:     String;
begin
  BLArea := AContext.Connection.IOHandler.ReadLn;
  AContext.Connection.IOHandler.WriteLn(BLArea);
end;

procedure TForm1.ToolButton1Click(Sender: TObject);
var
  Str:    String;
begin
  idtcpclient1.IOHandler.WriteLn('Do Something');
  str := idtcpclient1.IOHandler.ReadLn;
  memo1.Lines.Add(Str);
end;

Everything works well.  The message is sent/received without issue.

When I replace it with the following, the readstream in the server never
returns.  I'm missing something that is probably very obvious, but I haven't
quite worked out what that is.  The examples I've found on the internet
don't seem to do more than this, but something needs to tell the server that
it can grab the data and continue.

Any help would be appreciated.

Delphi 2006, Indy 10.1.5 (as supplied in D2006 install), winxp.

procedure TMyAppServer.IdTCPServer1Execute(AContext: TIdContext);
var
  MemStr:     TMemoryStream;
  BLArea:     String;
begin
  MemStr := TMemoryStream.Create;
  try
    AContext.Connection.IOHandler.ReadStream(MemStr);
    AContext.Connection.IOHandler.Write(MemStr, MemStr.Size);
  finally
    MemStr.Free;
  end;
end;

procedure TForm1.ToolButton1Click(Sender: TObject);
var
  MemStr: TMemoryStream;
  Str:    String;
begin
  MemStr := TMemoryStream.Create;
  try
    Str := 'My Message';
    MemStr.Write(Str[1], Length(Str));
    MemStr.Position := 0;
    idTCPClient1.IOHandler.Write(MemStr, MemStr.Size);
    MemStr.Clear;
    idTCPClient1.IOHandler.ReadStream(MemStr);
  finally
    MemStr.Free;
  end;
  memo1.lines.add('done');
end;

TIA

Eric Carman

Replies:

www.cryer.info
Managed Newsgroup Archive