A
amdcwf
Unregistered / Unconfirmed
GUEST, unregistred user!
程序如下:
server端:
function getWhatTypeToRece(TN:TTreeNode):integer;
var msg:string;
pStateSCS;
begin
result:=0;//错误
if (TN<>nil) then
begin
result:=pSCS(TN.Data)^.CodeState+1;
end;
end;
//
function assignMission(Socket:TCustomWinSocket):boolean;
var Info:AllCalInfo;
begin
result:=false;
if getAllCalInfo(Info) then
begin
if SizeOf(AllCalInfo)=Socket.SendBuf(Info,sizeOf(AllCalInfo)) then
result:=true
end;
end;
//
procedure TFrmServer.ServerClientRead(Sender: TObject;
Socket: TCustomWinSocket);
var
TN:TTreeNode;
pStateSCS;
txtRe:string;
begin
TN:=LocateInTVMsg(TVMsg,Socket.Handle);
case getWhatTypeToRece(TN) of
0:begin
end;
3:begin //申请任务消息
Echo.Lines.Add('Client(SocketID:'+IntTostr(Socket.Handle)+')'+'-申请任务');
TVMSg.Items.AddChild(TN,'申请任务');
if assignMission(Socket) then
begin
Inc(PSCS(TN.Data)^.CodeState);
PSCS(TN.Data)^.Discription:='申请任务';
Echo.Lines.Add('Server(SocketID:'+InTtostr(Socket.Handle)+')'+'-任务成功发出');
end;
end;
4:begin
while true do
begin
txtRe:=socket.ReceiveText;
if length(txtRe)>=1 then break;
end;
if txtRe='4' then
begin
Echo.Lines.Add('Client(SocketID:'+IntTostr(Socket.Handle)+')'+'-已获取计算任务的全部信息并进入计算...');
TVMSg.Items.AddChild(TN,'获取计算任务');
Inc(PSCS(TN.Data)^.CodeState);
PSCS(TN.Data)^.Discription:='计算中';
end else showmessage('未收到任务收到的确认信息');
end;
5:begin
end;
6:begin
end;
7:begin
end;
end;//endcase
end;
Client端:
function HandleState(Socket:TCustomWinSocket):string;
var calInfo:AllCalInfo;
reLong:integer;
begin
case clientStateCode of
2:begin
FrmClient.Echo.Lines.Add(Socket.ReceiveText);
FrmClient.Echo.Lines.Add('已收到欢迎信息,您可以申请任务了!');
end;
3:begin
reLong:=Socket.ReceiveLength;
if SizeOf(AllCalInfo)=socket.ReceiveBuf(CalInfo,reLong) then
begin
ClientStateCode:=4;
FrmClient.Echo.Lines.Add('成功获取计算任务信息,开始计算...');
FrmClient.CliState.Panels[0].Text:='计算中';
while true do
begin
if Socket.SendText('4')>=1 then break;//这个发出之后服务端不产生onserverclient事件,也就是说服务端没收到。 end;
//Common.CalMandel(CalInfo);
end else begin
end;
end;
4:begin
end;
5:begin
end;
6:begin
end;
7:begin
end;
end;//endcase
end;
procedure TFrmClient.ClientRead(Sender: TObject; Socket: TCustomWinSocket);
begin
HandleState(Socket);
end;
server端:
function getWhatTypeToRece(TN:TTreeNode):integer;
var msg:string;
pStateSCS;
begin
result:=0;//错误
if (TN<>nil) then
begin
result:=pSCS(TN.Data)^.CodeState+1;
end;
end;
//
function assignMission(Socket:TCustomWinSocket):boolean;
var Info:AllCalInfo;
begin
result:=false;
if getAllCalInfo(Info) then
begin
if SizeOf(AllCalInfo)=Socket.SendBuf(Info,sizeOf(AllCalInfo)) then
result:=true
end;
end;
//
procedure TFrmServer.ServerClientRead(Sender: TObject;
Socket: TCustomWinSocket);
var
TN:TTreeNode;
pStateSCS;
txtRe:string;
begin
TN:=LocateInTVMsg(TVMsg,Socket.Handle);
case getWhatTypeToRece(TN) of
0:begin
end;
3:begin //申请任务消息
Echo.Lines.Add('Client(SocketID:'+IntTostr(Socket.Handle)+')'+'-申请任务');
TVMSg.Items.AddChild(TN,'申请任务');
if assignMission(Socket) then
begin
Inc(PSCS(TN.Data)^.CodeState);
PSCS(TN.Data)^.Discription:='申请任务';
Echo.Lines.Add('Server(SocketID:'+InTtostr(Socket.Handle)+')'+'-任务成功发出');
end;
end;
4:begin
while true do
begin
txtRe:=socket.ReceiveText;
if length(txtRe)>=1 then break;
end;
if txtRe='4' then
begin
Echo.Lines.Add('Client(SocketID:'+IntTostr(Socket.Handle)+')'+'-已获取计算任务的全部信息并进入计算...');
TVMSg.Items.AddChild(TN,'获取计算任务');
Inc(PSCS(TN.Data)^.CodeState);
PSCS(TN.Data)^.Discription:='计算中';
end else showmessage('未收到任务收到的确认信息');
end;
5:begin
end;
6:begin
end;
7:begin
end;
end;//endcase
end;
Client端:
function HandleState(Socket:TCustomWinSocket):string;
var calInfo:AllCalInfo;
reLong:integer;
begin
case clientStateCode of
2:begin
FrmClient.Echo.Lines.Add(Socket.ReceiveText);
FrmClient.Echo.Lines.Add('已收到欢迎信息,您可以申请任务了!');
end;
3:begin
reLong:=Socket.ReceiveLength;
if SizeOf(AllCalInfo)=socket.ReceiveBuf(CalInfo,reLong) then
begin
ClientStateCode:=4;
FrmClient.Echo.Lines.Add('成功获取计算任务信息,开始计算...');
FrmClient.CliState.Panels[0].Text:='计算中';
while true do
begin
if Socket.SendText('4')>=1 then break;//这个发出之后服务端不产生onserverclient事件,也就是说服务端没收到。 end;
//Common.CalMandel(CalInfo);
end else begin
end;
end;
4:begin
end;
5:begin
end;
6:begin
end;
7:begin
end;
end;//endcase
end;
procedure TFrmClient.ClientRead(Sender: TObject; Socket: TCustomWinSocket);
begin
HandleState(Socket);
end;