SvrMain.pas
资源名称:P2P.rar [点击查看]
上传用户:zhanghw123
上传日期:2021-11-15
资源大小:312k
文件大小:1k
源码类别:
P2P编程
开发平台:
Delphi
- Unit SvrMain;
- Interface
- Uses
- SysUtils, Classes, Controls, Forms,
- StdCtrls, ComCtrls, ToolWin,
- P2pServer, IDSocketHandle;
- Type
- TFrmMain = Class(TForm)
- ToolBar: TToolBar;
- CmdStart: TToolButton;
- CmdStop: TToolButton;
- CmdQuit: TToolButton;
- TxtLog: TMemo;
- Procedure CmdStartClick(Sender: TObject);
- Procedure CmdStopClick(Sender: TObject);
- Procedure CmdQuitClick(Sender: TObject);
- Procedure FormCreate(Sender: TObject);
- Procedure FormClose(Sender: TObject; Var Action: TCloseAction);
- Private
- IsRun: Boolean;
- P2p: TP2pServer;
- Public
- { Public declarations }
- End;
- Var
- FrmMain: TFrmMain;
- Implementation
- {$R *.dfm}
- Procedure TFrmMain.CmdStartClick(Sender: TObject);
- Var
- Binding: TIDSocketHandle;
- Begin
- If IsRun Then Exit;
- TxtLog.Clear;
- P2p.Bindings.Clear;
- Binding := P2p.Bindings.Add;
- Binding.IP := '0.0.0.0';
- Binding.Port := 9890;
- P2p.StartServer;
- IsRun := true;
- End;
- Procedure TFrmMain.CmdStopClick(Sender: TObject);
- Begin
- P2p.StopServer;
- IsRun := false;
- End;
- Procedure TFrmMain.CmdQuitClick(Sender: TObject);
- Begin
- CmdStop.Click;
- Sleep(300);
- If P2p <> Nil Then FreeAndNil(P2p);
- Application.Terminate;
- End;
- Procedure TFrmMain.FormCreate(Sender: TObject);
- Begin
- P2p := TP2pServer.Create(TxtLog);
- CmdStart.Click;
- End;
- Procedure TFrmMain.FormClose(Sender: TObject; Var Action: TCloseAction);
- Begin
- CmdQuit.Click;
- End;
- End.