首先,定义一个全局的记录和指针,在TCPServerExecute事件中,拦截连接的信息 with AThread.Connection do ....., 使用上述的记录来存放新连接客户端的地址等信息,并循环记录的个数,用该指针对已经连接的客户端进行通讯,逐个通知该通知的客户。
var Alist: Tlist; i: Integer; begin Alist := IdTCPServer1.Threads.LockList; for i := 0 to Alist.Count-1 do begin TIdPeerThread(Alist.Items[i]).Connection.WriteLn('12345678'); //TIdPeerThread(Alist.Items[i]).Connection.WriteInteger(i); end; IdTCPServer1.Threads.UnlockList;
with AThread.Connection do .....,
使用上述的记录来存放新连接客户端的地址等信息,并循环记录的个数,用该指针对已经连接的客户端进行通讯,逐个通知该通知的客户。
Alist: Tlist;
i: Integer;
begin
Alist := IdTCPServer1.Threads.LockList;
for i := 0 to Alist.Count-1 do
begin
TIdPeerThread(Alist.Items[i]).Connection.WriteLn('12345678');
//TIdPeerThread(Alist.Items[i]).Connection.WriteInteger(i);
end;
IdTCPServer1.Threads.UnlockList;
TIdPeerThread(Alist.Items[i]).Connection.WriteLn('12345678');
这个函数是Server向Client端发数据吧?Client端怎么才能接收到呢?通常都是Client主动向Server发数据,然后等待接收数据。
你可以参考一下飞鸽的源码,里面什么都有了
服务器 对所有的socket连接广播就行了我这里有个样例 要看么