indy
来源:互联网 发布:初学者如何学习编程 编辑:程序博客网 时间:2024/05/17 21:46
indy9:
//一个简单的客户端连接信息数据结构
type PClient = ^TClient;
TClient = record // 客户端连接信息的类
clientip :String[50];//ip
Thread : Pointer;//指向一个客户端连接的指针
end;
Clients : TThreadList; //客户端连接列表
//连接事件
procedure TFrmDataCom.IdTCPServerConnect(AThread: TIdPeerThread);
var
NewClient: PClient;//新的连接
buf :array[0..1] of byte;
begin
new(NewClient);//分配内存
NewClient.Thread := AThread;
AThread.Data :=TObject(NewClient);
try
Clients.LockList.Add(NewClient); //在列表中添加新的对象
finally
Clients.UnlockList;
end;
end;
//断开事件
procedure TFrmDataCom.IdTCPServerDisconnect(AThread: TIdPeerThread);
var
ActClient: PClient;
id,index :integer;
begin
ActClient := Pointer(AThread.Data);
try
Clients.LockList.Remove(ActClient); //从list中移除客户端
finally
Clients.UnlockList;
end;
try
Dispose(ActClient);
AThread.Data := nil;
except
end;
end;
//接收数据事件
procedure TFrmDataCom.IdTCPServerExecute(AThread: TIdPeerThread);
var
recvResult :integer;
begin
if not AThread.Terminated and AThread.Connection.Connected then
begin
try
recvResult := AThread.Connection.Socket.Recv(tmprbuf,sizeof(tmprbuf));//接收数组
if(recvResult = -1) or (recvResult=0) then
begin
AThread.Connection.Disconnect;
end
else
begin
//处理数据
end;
except
AThread.Connection.Disconnect;
end;
end;
//关闭所有的连接
procedure TFrmDataCom.CloseAllClient;
var
i:Integer;
AThread: TIdPeerThread;
Client :PClient;
begin
try
with Clients.LockList do
begin
for i:=0 to Count-1 do
begin
try
AThread :=TIdPeerThread(PClient(Items[i]).Thread);
AThread.Connection.InputBuffer.Clear;
AThread.Connection.Disconnect;
except
end;
end;
end;
finally
Clients.UnlockList;
end;
IdTCPServer.Active :=false;
end;
indy当有客户端在线时候还要自己去disconn,真是无语。。。。。。。。。。不知道是不是这个样子???
- indy
- indy编程
- Indy + TStringList
- Indy 9.0
- indy安装
- Indy IdTcpserver
- 为何选择Indy?
- 为何选择Indy?
- Indy的安装问题
- 学习indy组件
- indy阻塞模式
- Indy tcp server
- Indy tcp client
- Upgrading to Indy 10
- indy Socket 编程
- 为何选择Indy?
- Indy 9 FTP 安装
- indy 实现http proxy
- Ant之Target 和Properity:
- Mpeg2——TS简单分析
- (转)ECC加密算法入门介绍
- 附加数据库失败,无法升级数据库,因为它是只读的
- (转载)RHEL/CentOS 5.5使用第三方软件库(EPEL与RPMForge、RPMFusion软件库)
- indy
- SQLServer 数据库的数据汇总完全解析(WITH ROLLUP)
- 恢复快速启动栏显示桌面按钮
- 正则匹配函数——regcomp和regexec
- Visual Studio中使用正则表达式进行代码规范的检查
- T-sql 创建约束
- 还是find 强大
- 云计算,互联网反攻的号角
- 有关DSP程序编写和调试