"> Button3.caption: = 'Ñêðûòü Гà ñòðîéêè'; end end; end.
Код програми сервера:
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, IdSocketHandle, StdCtrls, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient, IdUDPBase, IdUDPClient, ExtCtrls, IdUDPServer , IdTCPServer, jpeg, Buttons, FileCtrl, WinSock; type TForm1 = class (TForm) s: TIdUDPServer; c: TIdUDPClient; Eport: TEdit; Button2: TButton; Edit1: TEdit; end; var Form1: TForm1; implementation {$ R *. dfm} function TForm1.GetLocalIP: String; const WSVer = $ 101; var wsaData: TWSAData; P: PHostEnt; Buf: array [0. .127] of Char; begin Result: =''; if WSAStartup (WSVer, wsaData) = 0 then begin if GetHostName (@ Buf, 128) = 0 then begin P: = GetHostByName (@ Buf); if P <> ; nil then Result: = iNet_ntoa (PInAddr (p ^. h_addr_list ^) ^); end; WSACleanup; end; end; procedure TForm1.sUDPRead (Sender: TObject; AData: TStream; ABinding: TIdSocketHandle); var i: integer; zap: boolean; mas: array [0 .. 1000] of char; str, pg: string; begin zap: = false; str: =''; Adata.Read (mas, 100); for i: = 1 to 1000 do begin if mas [i] <> '!' then str: = str + mas [i] elseLabel1: TLabel; Label2: TLabel; Edit2: TEdit; RadioButton1: TRadioButton; RadioButton2: TRadioButton; RadioButton3: TRadioButton; RadioButton4: TRadioButton; Label3: TLabel; Label4: TLabel; function GetLocalIP: String ; procedure sUDPRead (Sender: TObject; AData: TStream; ABinding: TIdSocketHandle); procedure Button2Click (Sender: TObject); procedure FormCreate (Sender: TObject); private {Private declarations} public {Public declarations } break; end; if mas [0] = 'p' then begin c.Host: = str; c.Port: = strtoint (eport.text) ; c.Active: = true; c.Send ('p1o'); c.Active: = false; end; if mas [0] = 'z' then begin c.Host: = str; c.Port: = strtoint (eport.text); c.Active: = true; if RadioButton1.Checked then pg: = 's'; if RadioButton2.Checked then pg: = 'p'; if RadioButton3.Checked then pg: = 'o'; if RadioButton4.Checked then pg: = 'd'; c.Send ('z' + pg + edit2.Text + '#'); c.Active: = false; end; end; procedure TForm1.Button2Click (Sender: TObject); begin s.Active: = true; end; procedure TForm1.FormCreate (Sender: TObject); begin label4.Caption: = Form1.GetLocalIP end; end.
Висновок
Одержаний програмний продукт, який реалізує відмовостійку систему на основі клієнт серверної технології. Програма перевірена на практиці. У разі втрати зв'язку з провідним сервером клієнт успішно перемикається на альтернативний. Поставлена ​​задача виконана. br/>