Newsgroups : Borland : borland.public.delphi.internet.winsock : 2007 Dec : Re: TidTCPServer from delphi 6
| Subject: | Re: TidTCPServer from delphi 6 |
| Posted by: | "Nicoara Adrian" (adisoft..@yahoo.com) |
| Date: | Thu, 27 Dec 2007 13:21:06 |
thanks a lot :) i made it
I want to make a a crossplatform server aplication. This is why i use Indy
from delphi 6. Hopefully i can compile it under kylie without too many
modifications.
This is the code:
procedure SendMSG(socket:word;msg:string);
var
Count: Integer;
List : TList;
begin
List := form1.tcpSrv.Threads.LockList;
try
for Count := 0 to List.Count -1 do
if TIdPeerThread(List.Items[Count]).ThreadID=socket then
begin
try
TIdPeerThread(List.Items[Count]).Connection.WriteLn(Msg);
except
TIdPeerThread(List.Items[Count]).Stop;
end;
end;
finally
form1.tcpSrv.Threads.UnlockList;
end;
end;
"Remy Lebeau (TeamB)" <no.spam@no.spam.com> wrote in message
news:477177e5$1@newsgroups.borland.com...
>
> "Nicoara Adrian" <adisoftbn@yahoo.com> wrote in message
> news:477138fc@newsgroups.borland.com...
>
>> I'm using indy from delphi 6.
>
> Then you are likely using Indy 8, which is outdated and no longer
> supported.
>
>> when a client connects i save his socket number
>
> You are not saving the underlying TSocket handle, are you?
>
>> on an array.
>
> Is your array protected from multi-threaded access?
>
>> how do i send an message from server to all clients
>
> You have to loop through the list pointed to by the server's Threads
> property. Each entry is a pointer to a TIdPeerThread object. You can
> write
> to each client via that object, just like you normally do when replying to
> client messages. You will have to implement your own locking mechanism,
> though, so your server's broadcast messages do not overlap client message
> replies that may be sent at the same time. Indy does not prevent multiple
> threads from reading from, or writing to, a socket from multiple threads
> at
> the same time, so you have to manage that yourself manually. If you go to
> http://www.deja.com and search the newsgroup archives, examples of a few
> different techniques have been posted many times before.
>
>> or to a specified client via socket number ?
>
> Again, you have to loop through the server's Threads list looking for the
> TIdPeerThread object that you are interested in.
>
>
> Gambit