🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.cppbuilder.internet.socket
7 messages
7 total messages Started by Lapo Guidi Tue, 12 Dec 2006 00:52
TIdTCPServer and TIdTCPClient
#1635
Author: Lapo Guidi
Date: Tue, 12 Dec 2006 00:52
17 lines
1473 bytes
Hi all,
I have a problem using TIdTCPServer and TIdTCPClient together.
I try to explain better:
In the server and client side I have a TStringGrid.
The clients connect to the server and can update every cell on the string 
grid sending a command to the server.
The server receive the command and update the cell on his string grid.
Now the server send to all the clients connected a sort of command to tell 
them to update the right cell.
Now the question: There's a way to do that without a TTimer (at client side) 
with a ReadLn inside?
Should I use a Thread?
Could somebody help me?

Thanks very much.

Lapo 
Re: TIdTCPServer and TIdTCPClient
#1636
Author: Remy Lebeau (TeamB)
Date: Tue, 12 Dec 2006 05:04
12 lines
1238 bytes
"Lapo Guidi" <lapoguidi@inwind.it> wrote in message
news:457dfd00$1@newsgroups.borland.com...

> There's a way to do that without a TTimer (at client side) with a
> ReadLn inside? Should I use a Thread?

Yes.  Indy is not an asynchronous library, so asynchronous operations have
to be performed synchronously inside their own threads.


Gambit
Re: TIdTCPServer and TIdTCPClient
#1637
Author: Lapo Guidi
Date: Tue, 12 Dec 2006 22:49
12 lines
1420 bytes
Yes, I supposed that.

At client side I do that:
when user update a cell at Row, Col I send a command to the server
TCPClient->SendCmd("UPDATE "+IntToStr(Row)+" "+IntToStr(Col));
So the Server receive the command and Client get Reply and Response back.
But how could I code a Thread at client side to receive the data from the 
Server when the Client didn't send a command?
Could you help me giving me a little snip of code?
Thanks

Lapo 
Re: TIdTCPServer and TIdTCPClient
#1638
Author: Lapo Guidi
Date: Tue, 12 Dec 2006 23:14
11 lines
1351 bytes
Well, I coded a TThread descendant that perform a ReadLn without timeout (I 
found a previous posted answer you gave to somebody hehe).
But I have again a question:
when the Client send a command with SendCmd, function doesn't return untill 
Reply and Response;
the receiving thread I coded will steal the Reply and the Response that 
SendCmd is waiting for?
I'm a bit confused and I'm sorry if these are dumb questions.
Thanks.

Lapo 
Re: TIdTCPServer and TIdTCPClient
#1639
Author: Remy Lebeau (TeamB)
Date: Wed, 13 Dec 2006 00:17
22 lines
1779 bytes
"Lapo Guidi" <lapoguidi@inwind.it> wrote in message
news:457f31bf@newsgroups.borland.com...

> At client side I do that:
> when user update a cell at Row, Col I send a command to the server
> TCPClient->SendCmd("UPDATE "+IntToStr(Row)+" "+IntToStr(Col));

That will not work anymore if you use a reading thread, as SendCmd()
performs its own reading internally.  So you have the possibility of the
thread receiving data that SendCmd() is expecting, and vice versa.

> So the Server receive the command and Client get Reply and Response
> back. But how could I code a Thread at client side to receive the data
> from the Server when the Client didn't send a command?

Simply call one of the appropriate reading methods of the connection in a
loop for the lifetime of the thread.  Look at the source code of the
TIdTelnet component for an example.


Gambit
Re: TIdTCPServer and TIdTCPClient
#1640
Author: Remy Lebeau (TeamB)
Date: Wed, 13 Dec 2006 00:20
26 lines
2119 bytes
"Lapo Guidi" <lapoguidi@inwind.it> wrote in message
news:457f3780$1@newsgroups.borland.com...

> when the Client send a command with SendCmd, function doesn't return
> untill Reply and Response; the receiving thread I coded will steal the
Reply
> and the Response that SendCmd is waiting for?

Yes, it can (and vice versa, SendCmd() can steal data that the thread may be
waiting on).  Which is why you can't use SendCmd() anymore if you are using
a reading thread.  You will have to use WriteLn() instead, and then do all
of your reply processing inside of the thread as well.  So you are going to
have to design your data protocol in such as way that the thread will be
able to tell which packets are command replies and which ones are not.

One way around that is to wrap the connection in a critical section.  Then
you can "lock" the connection before calling SendCmd() and "unlock" it
afterwards.  Then the thread will not be able to read from the socket while
it is busy waiting for a command reply.

Othrwise, you will just have to go back to using a Timer again and forget
the thread altogether.


Gambit
Re: TIdTCPServer and TIdTCPClient
#1641
Author: Lapo Guidi
Date: Wed, 13 Dec 2006 01:14
4 lines
1064 bytes
Thanks very much Remy,
You helped me a lot as usual.

Lapo 
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