X
xuxiaohan
Unregistered / Unconfirmed
GUEST, unregistred user!
用 udp, 当需要更新 的时候, 从服务器(客户端也可以) 传递 更新指令 给客户 端, 这是最正统 的做法, 不要用Timer。
我有这样的例子。
var
Info: TBaseInfo;
do
cInfo: TDocInformation;
Files: array[0..1024] of char;
begin
fillChar(info, sizeof(info), 0);
AData.Position:=0;
AData.ReadBuffer(info, sizeof(info));
case info.dlg of
dmLogin:
begin
UdpClient.Host:=info.ip;
sendPkInfo(dmOnLine);
if userIndex(info.user)<>-1 then
userList[userIndex(info.user)]:=info.user+'^'+info.ip;
UserLogChange(info.user, true);
end;
dmOnLine:
begin
if userIndex(info.user)<>-1 then
userList[userIndex(info.user)]:=info.user+'^'+info.ip;
UserLogChange(info.user, true);
end;
dmOffLine:
if userList<>nil then
begin
if userIndex(info.user)<>-1 then
userList[userIndex(info.user)]:=info.user;
UserLogChange(info.user, false);
end;
[red]dmRefresh:[/red]
if assigned(mlist) then
Mlist.upDateData;
dmMessage:
begin
ReceiveMsg(info, AData);
end;
dmDocInfo:
begin
Adata.Position:=sizeof(info);
Adata.ReadBuffer(DocInfo, sizeof(Docinfo));
TfmNotify.ShowDocInfo(info,do
cInfo);
end;
dmFileTrans:
if findWindow('TfmReceiveFile', nil)=0 then
begin
AData.Position:=sizeof(info);
Adata.Read(Files, Adata.Size-sizeof(info));
TfmReceiveFile.CreateExe(info.user, info.ip, Files, info.msg);
end;
dmReadFromSvr: ReadMsgFromSever;
end;
我有这样的例子。
var
Info: TBaseInfo;
do
cInfo: TDocInformation;
Files: array[0..1024] of char;
begin
fillChar(info, sizeof(info), 0);
AData.Position:=0;
AData.ReadBuffer(info, sizeof(info));
case info.dlg of
dmLogin:
begin
UdpClient.Host:=info.ip;
sendPkInfo(dmOnLine);
if userIndex(info.user)<>-1 then
userList[userIndex(info.user)]:=info.user+'^'+info.ip;
UserLogChange(info.user, true);
end;
dmOnLine:
begin
if userIndex(info.user)<>-1 then
userList[userIndex(info.user)]:=info.user+'^'+info.ip;
UserLogChange(info.user, true);
end;
dmOffLine:
if userList<>nil then
begin
if userIndex(info.user)<>-1 then
userList[userIndex(info.user)]:=info.user;
UserLogChange(info.user, false);
end;
[red]dmRefresh:[/red]
if assigned(mlist) then
Mlist.upDateData;
dmMessage:
begin
ReceiveMsg(info, AData);
end;
dmDocInfo:
begin
Adata.Position:=sizeof(info);
Adata.ReadBuffer(DocInfo, sizeof(Docinfo));
TfmNotify.ShowDocInfo(info,do
cInfo);
end;
dmFileTrans:
if findWindow('TfmReceiveFile', nil)=0 then
begin
AData.Position:=sizeof(info);
Adata.Read(Files, Adata.Size-sizeof(info));
TfmReceiveFile.CreateExe(info.user, info.ip, Files, info.msg);
end;
dmReadFromSvr: ReadMsgFromSever;
end;