🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.cppbuilder.internet.socket
2 messages
2 total messages Started by Michele Santucci Wed, 30 Jun 2004 13:05
TIdTCPServer (Indy) problems
#5650
Author: Michele Santucci
Date: Wed, 30 Jun 2004 13:05
30 lines
2071 bytes
Hello ng,

I'm writing a test server using the Indy TIdTCPServer and I have some
problems:
I need to write a server that's capable of accepting just one connection and
then show the data got from the peer on a TListBox.
I wrote all the code and it partially works but I still need some help on
the connection / disconnection mechanism.

My first doubt is about the OnExchange event .. is it triggered just when
the server spawn for the first time the peer thread or each time something
happens to the peer connection (read data, write data, disconnection)?

Then.. what's the best way to handle safely peer's disconnections and server
shutdowns? I tried in several ways but I always have errors of all kinds.

Are there any samples to show how to use properly this component? I already
read all the indy's samples given along with Borland C++ Builder 6 Pro but I
haven't found anything useful ... (they are TOO simple: since most of
connection are closed after the first data exchange).


-- 
================================
Michele Santucci
Software Development Manager
Celin Avio S.r.l.
Via Fontevivo, 21/M 19100 La Spezia
tel. +39-0187564080
================================
Re: TIdTCPServer (Indy) problems
#5652
Author: Remy Lebeau (TeamB)
Date: Wed, 30 Jun 2004 17:24
57 lines
2647 bytes
"Michele Santucci" <michele.santucci.nospam@nospam.celinavio.it> wrote in
message news:40e2baf1@newsgroups.borland.com...

> I need to write a server that's capable of accepting
> just one connection

Use TIdSimpleServer instead of TIdTCPServer.  TIdSimpleServer is a
simplified TIdTCPServer specifically designed to handle a single connection
at a time.

> My first doubt is about the OnExchange event ..

There is no OnExchange event in Indy.  Perhaps you mean OnExecute?

> is it triggered just when the server spawn for the first time
> the peer thread or each time something happens to the peer
> connection (read data, write data, disconnection)?

Assuming you do mean OnExecute, then it is triggered in a loop for the
lifetime of the connection regardless of what is actually happening on the
socket.  It is the inner body of a "while not Terminated" loop for
TThread.Execute(), ie:

    procedure TIdThread.Execute;
    begin
        //...
        while not Terminated do begin
            //...
            BeforeRun;
            while not Stopped do Run;
            AfterRun;
        end;
        //...
    end;

    procedure TIdPeerThread.Run;
    begin
        //...
        // triggers the TIdTCPServer.OnExecute event
        Connection.Server.DoExecute(Self)
        //...
    end;

> Then.. what's the best way to handle safely peer's
> disconnections and server shutdowns?

All of that is already handled for you, as long as you are not doing your
own exception handling in the OnExecute event handler that prevents Indy
exceptions from reaching back to the TIdTCPServer for its own processing.

> I tried in several ways but I always have errors of all kinds.

Please be more specific.


Gambit
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads