Newsgroups : Borland : borland.public.delphi.internet.winsock : 2007 Nov : Re: Indy TCP Bridge

www.cryer.info
Managed Newsgroup Archive

Re: Indy TCP Bridge

Subject:Re: Indy TCP Bridge
Posted by:"Jamie Dale" (jamie.da..@yahoo.com)
Date:Wed, 28 Nov 2007 23:16:48

Hi Richard

Sorry I'm late, but I asked this almost same question just a few weeks ago.
Remy kindly supplied me with some sample code (and trust me it's rather
enlightening) so I've gone thread hunting and dug it up for you. This sample
code is courtesy of Remy Lebeau:

    procedure TForm1.TCPServerExecute(AThread: TIdPeerThread);
    var
        FileSize: Integer;
        BufSize: Integer;
        buffer: array[0..1023] of Byte;
    begin
        FileSize := AThread.Connection.ReadInteger;
        while FileSize > 0 do
        begin
            BufSize := min(FileSize, 1024);
            AThread.Connection.ReadBuffer(buffer[0], BufSize);
            // send buffer up to BufSize bytes to target client ...
            Dec(FileSize, BufSize);
        end;
    end;

Basically, stick that in the server's execute handler,  when it's read 1Kb
from the file stream, you then write that to the target client using
sendstream. You obviously need to find and lock the targets AThread/Context
first (to stop other threads writing to it) using something like a
TCriticalSection before using writestream.

I'd recommend having a TObject class - something like

Client: TObject(class)
    Public
    UserName: String;
    AThread: TIdPeerThread;
    CS: TCriticalSection;
    constructor Create;
    destructor Destroy;
    end;

Obviously in the create and destroy procedures you need to create/destroy
the CS - TCriticalSection (CS := TCriticalSection.Create; & CS.Free;).
Remember to keep the Client objects in a TList or TThreadList so that you
can access each and everyone of them with a pointer and
access,modify,destroy when needed. Again, most of this has come from Remy
Lebeau in the past.

JD


"Richard Milner" <richard-milner@gmail.com> wrote in message
news:474ae382@newsgroups.borland.com...
>I am having issues with streamlining an application, and am sure I have
>missed something simple.
>
> I have a client and server application, Client A sends a file to Client B
>
> CA -> Server -> CB
>
> This is simple, however the server is saving the file locally then on
> completing sending it off to the client, is there (how do I) send the data
> as i am reciving it, ensuring the steam is constant, code samples would be
> appreciated.
>
> Thanks

Replies:

none

In response to:

www.cryer.info
Managed Newsgroup Archive