Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How can i send a string to all connections in my TIdTcpServer

2,253 views
Skip to first unread message

Davis

unread,
Aug 16, 2002, 10:08:44 AM8/16/02
to
Hi,
I am starting with Indy, and i need to send a string to all clients
connected in my TIdTcpServer. And where i can get the information about each
socket connected to my server like Ip, host,...

Thanks.


Tony Caduto

unread,
Aug 15, 2002, 1:21:34 PM8/15/02
to
var
Count: Integer;
List : TList;
begin
List := tcpServer.Threads.LockList;
try
for Count := 0 to List.Count -1 do
begin

TIdPeerThread(List.Items[Count]).Connection.WriteLn('displaystring');//write
the command to the client
TIdPeerThread(List.Items[Count]).Connection.WriteLn('This is
a test string bla bla');
end;

finally
tcpserver.threads.UnlockList;
end;


of course you will have to have a thread on the client that listens for
incoming commands


Tony Caduto

unread,
Aug 16, 2002, 11:53:38 AM8/16/02
to
Well, just to send a string you don't need the ip, the connection has it
already.
but if you just want to grab it for whatever reason you can simply use
connection.peerIP

Note that if the user is behind a proxy or NAT router the peer IP will be
that of the router.
You should be sending the clients IP when they connect and storing it in the
data property of the connection, then you can do stuff like compare the
actual IP to the peer IP and determin if they are behind a router, if they
are the IPs will be different.

Tony Caduto

"TheBigBadWolf" <thebig...@gmx.at> wrote in message
news:3d5cbda8@dnews...
> and how can i get all the ip addresses of the clients?
> thanx
>
>
> "Tony Caduto" <tony....@micorp.com> schrieb im Newsbeitrag
> news:3d5be31d@dnews...

Tony Caduto

unread,
Aug 16, 2002, 12:04:32 PM8/16/02
to
Here is exactly how to do it with indy 9, make sure you have
IdIOHandlerSocket in your uses.
if you need the port just say binding.peerport.

Just write a function that returns a tstringlist and when you loop through
add the ips to the list, piece of cake :-)

for Count := 0 to List.Count -1 do
begin

TIdPeerThread(List.Items[Count]).Connection.WriteLn('displaystring');//write
the command to the client

TIdPeerThread(List.Items[Count]).Connection.WriteLn('This is a test string
bla bla');

theIP:=
TIdIOHandlerSocket(TIdPeerThread(List.Items[Count]).Connection.IOHandler).Bi
nding.peerip;
end;

"Tony Caduto" <tony....@micorp.com> wrote in message
news:3d5be31d@dnews...

Johannes Berg

unread,
Sep 5, 2002, 7:01:16 AM9/5/02
to
On Thu, 05 Sep 2002 11:09:26 +0100, trevor wrote:

> What if I wanted to send a mesage to all the clients when the server
> exited abnormally (i.e. Ctrl + Alt + Delete)
>
> Where would this code go. I want to kill all existing clients when the
> server crashes.

That code would go in the client ;-)
If you simply kill the server it won't execute a single more instruction,
so it can't let the clients know.
Therefore, you have to have an "alive-check" in your clients.

johannes

Michael Winter

unread,
Sep 5, 2002, 4:50:14 PM9/5/02
to
Johannes Berg schrieb:

>
> On Thu, 05 Sep 2002 11:09:26 +0100, trevor wrote:
>
> > What if I wanted to send a mesage to all the clients when the server
> > exited abnormally (i.e. Ctrl + Alt + Delete)

> Therefore, you have to have an "alive-check" in your clients.

I don't think. If the server somehow dies, Windows (NT of course) almost
always frees all its handles. On the client side, you will get a
disconnect at this point.

However, this is not true if someone unplugs the network cable or some
router facility on the way fails.

-Michael

0 new messages