Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unit Unit1;
- {$RTTI EXPLICIT METHODS([]) PROPERTIES([]) FIELDS([])}
- interface
- uses
- Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
- Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, System.Win.ScktComp,
- Vcl.ExtCtrls, IdHTTP;
- type
- TForm1 = class(TForm)
- ServerSocket1: TServerSocket;
- Memo1: TMemo;
- iscon: TTimer;
- CMDS: TTimer;
- TrayIcon1: TTrayIcon;
- procedure ServerSocket1ClientConnect(Sender: TObject;
- Socket: TCustomWinSocket);
- procedure ServerSocket1ClientDisconnect(Sender: TObject;
- Socket: TCustomWinSocket);
- procedure ServerSocket1ClientRead(Sender: TObject;
- Socket: TCustomWinSocket);
- procedure isconTimer(Sender: TObject);
- procedure ServerSocket1ClientError(Sender: TObject;
- Socket: TCustomWinSocket; ErrorEvent: TErrorEvent;
- var ErrorCode: Integer);
- procedure FormClose(Sender: TObject; var Action: TCloseAction);
- procedure FormCreate(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- //showmessage(
- end;
- var
- Form1: TForm1;
- implementation
- {$R *.dfm}
- procedure TForm1.ServerSocket1ClientConnect(Sender: TObject;
- Socket: TCustomWinSocket);
- begin
- try
- Socket.SendText('GiveInfo|');
- trayicon1.BalloonTitle := 'Info!';
- trayicon1.BalloonHint := 'Received ->: Status 200';
- TrayIcon1.ShowBalloonHint;
- Except
- end;
- end;
- procedure TForm1.ServerSocket1ClientDisconnect(Sender: TObject;
- Socket: TCustomWinSocket);
- begin
- try
- trayicon1.BalloonTitle := 'Info!';
- trayicon1.BalloonHint := 'Received ->: Status 512';
- TrayIcon1.ShowBalloonHint;
- socket.Close;
- Except
- end;
- end;
- procedure TForm1.ServerSocket1ClientError(Sender: TObject;
- Socket: TCustomWinSocket; ErrorEvent: TErrorEvent; var ErrorCode: Integer);
- begin
- Errorcode:= 0;
- end;
- const
- HTTP_RESPONSE_OK = 200;
- function GetPage(aURL: string): string;
- var
- Response: TStringStream;
- HTTP: TIdHTTP;
- begin
- Result := '';
- Response := TStringStream.Create('');
- try
- HTTP := TIdHTTP.Create(nil);
- try
- HTTP.Get(aURL, Response);
- if HTTP.ResponseCode = HTTP_RESPONSE_OK then begin
- Result := Response.DataString;
- end else begin
- // TODO -cLogging: add some logging
- end;
- finally
- HTTP.Free;
- end;
- finally
- Response.Free;
- end;
- end;
- procedure TForm1.ServerSocket1ClientRead(Sender: TObject;
- Socket: TCustomWinSocket);
- Var
- Data: string;
- SL: TStringList;
- begin
- SL := TStringList.Create;
- SL.Delimiter := '|';
- SL.StrictDelimiter := True;
- Data := Socket.ReceiveText;
- SL.DelimitedText := Data;
- if SL[0] = 'MyInfo' then
- begin
- trayicon1.BalloonTitle := 'Info!';
- trayicon1.BalloonHint := 'Received ->: ' + GetPage('api would go here');
- TrayIcon1.ShowBalloonHint;
- exit;
- end;
- if SL[0] = 'Close' then
- begin
- trayicon1.BalloonTitle := 'Info!';
- trayicon1.BalloonHint:= 'Received ->: ' + 'Bye :)';
- TrayIcon1.ShowBalloonHint;
- close;
- exit;
- end;
- end;
- procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
- begin
- end;
- procedure TForm1.FormCreate(Sender: TObject);
- begin
- Hide();
- WindowState := wsMinimized;
- TrayIcon1.Visible := True;
- TrayIcon1.Animate := True;
- TrayIcon1.ShowBalloonHint;
- end;
- procedure TForm1.isconTimer(Sender: TObject);
- begin
- if self.ServerSocket1.Socket.Connected then
- begin
- exit;
- CMDS.Enabled:= true;
- end
- else
- begin
- end;
- end;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement