请教高手TCP连接数限制
ccp 2006-08-12 12:50:01 我发现在同时连接100个左右以后的连接就连不上了。究竟是那方面的问题呢?
测试代码:3个文件
=============================
Unit3.pas
============================
unit Unit3;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, WSOcket, ComCtrls, StdCtrls;
type
TForm3 = class(TForm)
ListView1: TListView;
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
procedure COnnected(Sender: TObject; error: Word);
public
{ Public declarations }
end;
var
Form3: TForm3;
implementation
{$R *.dfm}
var
Clients: array of TWSocket;
procedure TForm3.COnnected(Sender: TObject; error: Word);
var
li: tlistitem;
begin
li := listView1.FindData(0, Sender, True, True);
if assigned(Li) then
begin
if error <> 0 then
begin
li.SubItems[0] := 'fail:' + Inttostr(error);
end
else
li.subitems[0] := 'ok:';
end;
end;
procedure TForm3.Button1Click(Sender: TObject);
var
I: Integer;
W: twsocket;
begin
for I := 0 to listview1.items.count - 1 do
begin
Clients[I].Addr := listView1.Items[I].Caption;
Clients[I].Port := '7000';
Clients[I].OnSessionConnected := Connected;
Clients[i].Connect;
end;
end;
procedure TForm3.FormCreate(Sender: TObject);
var
Strings: TStrings;
I: Integer;
li: tlistitem;
begin
strings := tstringlist.Create;
strings.LoadFromFile(GetCurrentDir + '\ip.txt');
setlength(clients, strings.count);
for I := 0 to strings.Count - 1 do
begin
Clients[I] := TWSocket.Create(nil);
li := listView1.Items.Add;
li.Caption := strings[i];
li.Data := clients[I];
li.SubItems.Add('');
end;
strings.Free;
end;
end.
======================================
Unit3.dfm
======================================
object Form3: TForm3
Left = 0
Top = 0
Caption = 'Form3'
ClientHeight = 238
ClientWidth = 337
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
OldCreateOrder = False
OnCreate = FormCreate
PixelsPerInch = 96
TextHeight = 13
object ListView1: TListView
Left = 0
Top = 0
Width = 337
Height = 238
Align = alClient
Columns = <
item
Caption = 'ip'
Width = 120
end
item
Caption = #29366#24577
end>
TabOrder = 0
ViewStyle = vsReport
end
object Button1: TButton
Left = 200
Top = 72
Width = 75
Height = 25
Caption = 'Button1'
TabOrder = 1
OnClick = Button1Click
end
end