Re: Begin Indy in BCB

Giganews Newsgroups
Subject: Re: Begin Indy in BCB
Posted by:  Remy Lebeau (TeamB) (gambit47.no.spam@no.spam.yahoo.com)
Date: Mon, 26 Jan 2004

"Bill Holt" <bi…@itsound.demon.co.uk> wrote in message
news:2fE4ibgIgBFAFw…@itsound.demon.co.uk...

> I'm trying to build a sort of chat program that uses XML data messages
> to carry the info, so naturally a demo chat app would be invaluable.

    --- client side ---

    void __fastcall TForm1::SendMessageClick(TObject *Sender)
    {
        AnsiString XML = "your xml here, preferrably in UTF8 format";

        if( !IdTCPClient1->Connected() )
            IdTCPClient1->Connect(5000);

        IdTCPClient1->WriteLn(XML);

        XML = IdTCPClient1->ReadLn();
        // process XML as needed...
    }

    --- server side ---

    void __fastcall TForm1::IdTCPServer1Execute(TIdPeerThread *AThread)
    {
        // depending on your version of BCB and Indy, you may
        // need to call one or the other of the following:

        AnsiString XML = AThread->Connection->ReadLn();
        // or
        // AnsiString XML = AThread->Connection->ReadLn(LF,
IdTimeoutDefault, -1);

        // process XML as needed...

        XML = "xml to return to the client";
        AThread->Connection->WriteLn(XML);
    }

> I'm having problems with basic concepts like whether I should connect
> each time a message has to be sent or whether the clients should stay
> connected throughout the session.

That depends on your actual needs, but typically it is better to remain
connected whenever possible.  If you are going to send messages to the same
receiver multiple times, it just makes more sense to keep that connection
open as long as it is needed.

Gambit

Replies

None

In response to

Begin Indy in BCB posted by Bill Holt on Sun, 25 Jan 2004