🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.cppbuilder.internet.socket
3 messages
3 total messages Started by Binzhong Zhou Wed, 25 Jan 2006 08:09
Indy TCP Server/Client handshake
#2851
Author: Binzhong Zhou
Date: Wed, 25 Jan 2006 08:09
22 lines
2158 bytes
Hi All,

I am a newbie for network programming. After I got the Indy9.0.50 work under 
my BCB6, I am ready to play around its function. I have made an simple TCP 
server/client code based on the BCB Indy example. I can send an command to 
the server to request a particular data and I can get response back from the 
server for the requested data. (WriteLn <sending command to server> & ReadLn 
<read data from server> are successively followed). I am very impressed that 
I can so quickly to do so. For small data set transfer, you may be able to 
get response immediately from the server. But what will happen if the 
requested data will not be transfered immediately from the server due the 
data need to be fetched from somewhere else on the server or the data is too 
big for instantaneous transfer? What is the best mechanism to handle this 
situation? Likewise, the server will similar issue from the client site if 
the server request data from the Client. The event handlings from the Indy 
TCP Client/Server do not give me much suggestions how to handle the 
situation.

Any suggestions even some snips are much appreciated.

Regards,
        Binzhonbg 
Re: Indy TCP Server/Client handshake
#2855
Author: Remy Lebeau (TeamB)
Date: Wed, 25 Jan 2006 18:51
38 lines
2759 bytes
"Binzhong Zhou" <Binzhong.Zhou@csiro.au> wrote in message
news:43d73188@newsgroups.borland.com...

> But what will happen if the requested data will not be transfered
> immediately from the server due the data need to be fetched from
> somewhere else on the server or the data is too big for instantaneous
> transfer?

Then you need to either:

1) just let it wait.  Maybe move the code into another thread so your
program is not blocked while the data is fetched.

2) design your protocol to work asynchronously.  When the client sends a
command, don't have it wait for a response immediately.  Let it cache the
command for later use and then go off and do other things, and use a thread
or timer to read the responses separately.  When a response is eventually
received, the client can match it up to the original command so it knows
what to do.  This also allows responses to be sent back in a different order
than the order that the commands were sent.  In other words, if the client
sends commands A and B, and A takes longer to process than B, then the
server can send a response back for B before A.

> Likewise, the server will similar issue from the client site if the server
> request data from the Client. The event handlings from the Indy TCP
> Client/Server do not give me much suggestions how to handle the situation.

Most Indy clients do not have asynchronous events.  If the server can send
an unsolicited command to the client at any moment, then the client has to
continuously poll the socket for incoming data.  A reading thread works best
for that, and that also plays into the asynchronous model above.  In your
transmitted data, put a small header at the beginning of each packet to
identify what the packet data is meant for - a response, a command from the
server, etc.


Gambit
Re: Indy TCP Server/Client handshake
#2867
Author: Binzhong Zhou
Date: Thu, 26 Jan 2006 13:25
5 lines
1184 bytes
Thanks Remy for your suggestions. I'll use the asynchronous model and put my 
data checking in a separated thread.

Cheers,
    Binzhong 
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