Параллельные алгоритмы

Листинг №7

Фрагменты кода клиента и сервера для организации распределенных вычислений в ЛВС

{Форма для клиентского окна}  
…   
TForm1 = class(TForm)  
…  
    ClientSocket1: TClientSocket;  
    ServerSocket1: TServerSocket;  
    procedure WmSocketMes(var Msg : TMessage); message wm_SocketMes;  
…  
end;  
…  
procedure TForm1.WmSocketMes(var Msg : TMessage);  
var  
  S: String;  
begin  
   case Msg.WParam of  
     0 : begin  
            S := CheckListBox1.Items[Msg.LParam];  
            ClientSocket1.Address := RemoveFirstWord(S);  
            ClientSocket1.Port := StrToInt(S);  
            ClientSocket1.Open;  
            if NumberAddr <> NumberCall then  
              Sleep(TimeSleep div 8)  
            else  
              Sleep(TimeSleep);  
            PostMessage(Handle,wm_SocketMes,1,Msg.LParam);  
         end;  
     1 : begin  
            NumberAddr := Msg.LParam;  
            ClientSocket1.Socket.SendText(AddrClient+' '+  
                                          PortClient+' '+  
                                          IntToStr(NumberAddr)+' '+  
                                          IntToStr(NumberCall)+' '+  
                                          CheckListBox2.Items[NumberCall]);  
            if NumberAddr <> NumberCall then  
              Sleep(TimeSleep div 8)  
            else  
              Sleep(TimeSleep);  
            ClientSocket1.Close;  
            CheckListBox2.State[NumberCall] := cbChecked;  
            ListSost[NumberCall] := wkGo;  
            if not Y then  
            begin  
              Inc(Msg.LParam);  
              if Msg.LParam < CheckListBox1.Items.Count then  
              begin  
                 inc(NumberCall);  
                 PostMessage(Handle,wm_SocketMes,0,Msg.LParam);  
              end;  
            end;  
         end;  
   end;  
   Msg.Result := 0;  
end;  
…  
{Форма для серверного окна}  
…  
TForm1 = class(TForm)  
    ServerSocket1: TServerSocket;  
    ClientSocket1: TClientSocket;  
  …  
 private  
  …  
  procedure WMQueryOpen(var Msg: TWMQueryOpen); message WM_QUERYOPEN;  
  procedure WmSocketMes(var Msg : TMessage); message wm_SocketMes;  
  …  
end;  
…  
procedure TForm1.WMQueryOpen(var Msg: TWMQueryOpen);  
begin  
  {Для минимизации формы}  
  Msg.Result := 0;  
end;  
procedure TForm1.WmSocketMes(var Msg : TMessage);  
begin  
   case Msg.WParam of  
     0 : begin  
            ClientSocket1.Address := Addr;  
            ClientSocket1.Port := StrToInt(Port);  
            ClientSocket1.Open;  
            Sleep(TimeSleep);  
            PostMessage(Handle,wm_SocketMes,1,Msg.LParam);  
         end;  
     1 : begin  
            ClientSocket1.Socket.SendText(IntToStr(Number)+' '+  
                                          IntToStr(NumberAddr));  
            Sleep(TimeSleep);  
            ClientSocket1.Close;  
            Inc(Msg.LParam);  
            if Msg.LParam < 1 then  
               PostMessage(Handle,wm_SocketMes,0,Msg.LParam);  
         end;  
   end;  
   Msg.Result := 0;  
end;  
…  

возврат


Наш канал на Youtube

1999 1 2 3 4 5 6 7 8 9 10 11 12
2000 1 2 3 4 5 6 7 8 9 10 11 12
2001 1 2 3 4 5 6 7 8 9 10 11 12
2002 1 2 3 4 5 6 7 8 9 10 11 12
2003 1 2 3 4 5 6 7 8 9 10 11 12
2004 1 2 3 4 5 6 7 8 9 10 11 12
2005 1 2 3 4 5 6 7 8 9 10 11 12
2006 1 2 3 4 5 6 7 8 9 10 11 12
2007 1 2 3 4 5 6 7 8 9 10 11 12
2008 1 2 3 4 5 6 7 8 9 10 11 12
2009 1 2 3 4 5 6 7 8 9 10 11 12
2010 1 2 3 4 5 6 7 8 9 10 11 12
2011 1 2 3 4 5 6 7 8 9 10 11 12
2012 1 2 3 4 5 6 7 8 9 10 11 12
2013 1 2 3 4 5 6 7 8 9 10 11 12
Популярные статьи
КомпьютерПресс использует