请教高手TCP连接数限制

ccp ccp 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
我发现在同时连接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
...全文

相关推荐

评论 6
收藏 已收藏
分享
返回顶部
ccp
网络通信/分布式开发 1,594 成员 32,944 内容