Y
ykjt
Unregistered / Unconfirmed
GUEST, unregistred user!
Unit Unit1;
Interface
Uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ScktComp;
Type
TForm1 = Class(TForm)
ListBox1: TListBox;
Button1: TButton;
ServerSocket1: TServerSocket;
Procedure FormCreate(Sender: TObject);
Procedure Button1Click(Sender: TObject);
Procedure FormDestroy(Sender: TObject);
PRIVATE
{ Private declarations }
PUBLIC
{ Public declarations }
End;
Var
Form1: TForm1;
Implementation
{$R *.dfm}
Procedure TForm1.FormCreate(Sender: TObject);
Begin
ServerSocket1 := TServerSocket.Create(self);
ServerSocket1.Active := True;
End;
Procedure TForm1.Button1Click(Sender: TObject);
Var
i: Integer;
Begin
ListBox1.Items.Clear;
For i := 0 To 1000 Do
Begin
ServerSocket1.Close;
ServerSocket1.Port := i;
Try
ServerSocket1.Open;
Except
ListBox1.Items.Add(IntToStr(i) + '端口已经打开');
End;
End;
End;
Procedure TForm1.FormDestroy(Sender: TObject);
Begin
ServerSocket1.Free;
End;
End.
运行时错误:通常每个套接字地址(协议/网络地址/端口)只允许使用一次
Interface
Uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ScktComp;
Type
TForm1 = Class(TForm)
ListBox1: TListBox;
Button1: TButton;
ServerSocket1: TServerSocket;
Procedure FormCreate(Sender: TObject);
Procedure Button1Click(Sender: TObject);
Procedure FormDestroy(Sender: TObject);
PRIVATE
{ Private declarations }
PUBLIC
{ Public declarations }
End;
Var
Form1: TForm1;
Implementation
{$R *.dfm}
Procedure TForm1.FormCreate(Sender: TObject);
Begin
ServerSocket1 := TServerSocket.Create(self);
ServerSocket1.Active := True;
End;
Procedure TForm1.Button1Click(Sender: TObject);
Var
i: Integer;
Begin
ListBox1.Items.Clear;
For i := 0 To 1000 Do
Begin
ServerSocket1.Close;
ServerSocket1.Port := i;
Try
ServerSocket1.Open;
Except
ListBox1.Items.Add(IntToStr(i) + '端口已经打开');
End;
End;
End;
Procedure TForm1.FormDestroy(Sender: TObject);
Begin
ServerSocket1.Free;
End;
End.
运行时错误:通常每个套接字地址(协议/网络地址/端口)只允许使用一次