服务端
Clients:TList;
已初始化并且有值
发送过程
var
Count: Integer;
List: TList;
begin
List := IdTCPServer1.Threads.LockList;
try
for Count := 0 to List.Count - 1 do
try
TIdPeerThread(List.Items[Count]).Connection.WriteBuffer(Clients, sizeof(Clients));
except
TIdPeerThread(List.Items[Count]).Stop;
end;
finally
IdTCPServer1.Threads.UnlockList;
end;
客户端
Clients: TList;
begin
Clients := TList.Create;
while not Terminated do //线程没有终止
begin
if LoadClient.Connected then
begin
try
LoadClient.ReadBuffer(Clients, SizeOf(Clients));
FMsg := IntToStr(Clients.Count); ----------在这里出错了呢。
except
on e: exception do
begin
FMsg := pchar(e.Message);
end;
end;
FMsg := IntToStr(Clients.Count); ----------在这里出错了呢。不知道怎么写了。
Clients:TList;
已初始化并且有值
发送过程
var
Count: Integer;
List: TList;
begin
List := IdTCPServer1.Threads.LockList;
try
for Count := 0 to List.Count - 1 do
try
TIdPeerThread(List.Items[Count]).Connection.WriteBuffer(Clients, sizeof(Clients));
except
TIdPeerThread(List.Items[Count]).Stop;
end;
finally
IdTCPServer1.Threads.UnlockList;
end;
客户端
Clients: TList;
begin
Clients := TList.Create;
while not Terminated do //线程没有终止
begin
if LoadClient.Connected then
begin
try
LoadClient.ReadBuffer(Clients, SizeOf(Clients));
FMsg := IntToStr(Clients.Count); ----------在这里出错了呢。
except
on e: exception do
begin
FMsg := pchar(e.Message);
end;
end;
FMsg := IntToStr(Clients.Count); ----------在这里出错了呢。不知道怎么写了。
允许发送一个数据结构。
若字段是字符串,必须固定大小。
type ...record