H
huangliang2005
Unregistered / Unconfirmed
GUEST, unregistred user!
服务器端代码:
procedure TfrmMain.IdTCPServerConnect(AThread: TIdPeerThread);
var
ClientBBOX: PBBOXIDClient;
listClients: TThreadList;
begin
listClients := TThreadList.create;
GetMem(ClientBBOX, SizeOf(TBBOXIDClient));
ClientBBOX.DNS := AThread.Connection.Socket.Binding.PeerIP;
ClientBBOX.Connected := Now;
ClientBBOX.LastAction := ClientBBOX.Connected;
ClientBBOX.Thread := AThread;
AThread.Data := TObject(ClientBBOX);
try
listClients.LockList.Add(ClientBBOX);
finally
listClients.UnlockList;
end;
end;
客户端代码:
procedure TForm1.idTCPClientCTRLConnected(Sender: TObject);
var
cmdinfo: tcmdinfo;
begin
try
cmdinfo.StartChar := 94;
cmdinfo.CmdType := 2; //命令类型
cmdinfo.interfaceID := 2; //接口号
cmdinfo.FunctID := 0; //功能号
cmdinfo.Subtype := 0; //子类型编号
cmdinfo.NoID := '020';
idTCPClientCTRL.WriteBuffer(cmdinfo, sizeof(tcmdinfo));
except
Mrunlog.Lines.Add(FormatDateTime('YYYYMMDDHHMMSS', Now) + '连接 控制中心 失败:');
end;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
var
cmdinfo: tcmdinfo;
begin
try
idTCPClientCTRL.Host := '192.168.0.88';
idTCPClientCTRL.port := 8088;
idTCPClientCTRL.Connect();
cmdinfo.StartChar := 94;
cmdinfo.CmdType := 2;
cmdinfo.interfaceID := 2;
cmdinfo.FunctID := 0;
cmdinfo.Subtype := 0;
cmdinfo.NoID := '020';
idTCPClientCTRL.WriteBuffer(cmdinfo, sizeof(tcmdinfo));
Mrunlog.Lines.Add(FormatDateTime('YYYYMMDDHHMMSS', Now) + '连接 控制中心 成功');
except
idTCPClientCTRL.Disconnect;
Mrunlog.Lines.Add(FormatDateTime('YYYYMMDDHHMMSS', Now) + '连接 控制中心 失败');
end;
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
if IdTCPClientCTRL.Connected then
idTCPClientCTRL.DisconnectSocket;
end;
问题:客户连接、断开几次后再连接到就在listClients.LockList.Add(ClientBBOX)这一句停止,不能执行下面的语句了.各位大侠帮帮忙,分不够再加
procedure TfrmMain.IdTCPServerConnect(AThread: TIdPeerThread);
var
ClientBBOX: PBBOXIDClient;
listClients: TThreadList;
begin
listClients := TThreadList.create;
GetMem(ClientBBOX, SizeOf(TBBOXIDClient));
ClientBBOX.DNS := AThread.Connection.Socket.Binding.PeerIP;
ClientBBOX.Connected := Now;
ClientBBOX.LastAction := ClientBBOX.Connected;
ClientBBOX.Thread := AThread;
AThread.Data := TObject(ClientBBOX);
try
listClients.LockList.Add(ClientBBOX);
finally
listClients.UnlockList;
end;
end;
客户端代码:
procedure TForm1.idTCPClientCTRLConnected(Sender: TObject);
var
cmdinfo: tcmdinfo;
begin
try
cmdinfo.StartChar := 94;
cmdinfo.CmdType := 2; //命令类型
cmdinfo.interfaceID := 2; //接口号
cmdinfo.FunctID := 0; //功能号
cmdinfo.Subtype := 0; //子类型编号
cmdinfo.NoID := '020';
idTCPClientCTRL.WriteBuffer(cmdinfo, sizeof(tcmdinfo));
except
Mrunlog.Lines.Add(FormatDateTime('YYYYMMDDHHMMSS', Now) + '连接 控制中心 失败:');
end;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
var
cmdinfo: tcmdinfo;
begin
try
idTCPClientCTRL.Host := '192.168.0.88';
idTCPClientCTRL.port := 8088;
idTCPClientCTRL.Connect();
cmdinfo.StartChar := 94;
cmdinfo.CmdType := 2;
cmdinfo.interfaceID := 2;
cmdinfo.FunctID := 0;
cmdinfo.Subtype := 0;
cmdinfo.NoID := '020';
idTCPClientCTRL.WriteBuffer(cmdinfo, sizeof(tcmdinfo));
Mrunlog.Lines.Add(FormatDateTime('YYYYMMDDHHMMSS', Now) + '连接 控制中心 成功');
except
idTCPClientCTRL.Disconnect;
Mrunlog.Lines.Add(FormatDateTime('YYYYMMDDHHMMSS', Now) + '连接 控制中心 失败');
end;
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
if IdTCPClientCTRL.Connected then
idTCPClientCTRL.DisconnectSocket;
end;
问题:客户连接、断开几次后再连接到就在listClients.LockList.Add(ClientBBOX)这一句停止,不能执行下面的语句了.各位大侠帮帮忙,分不够再加