第一个问题:我用delphi2010的IdTCPServer做个服务器希望能保持1000个以上的连接,不知道能不能支持的了?
第二个问题:
procedure TForm2.GPRSTCPServerExecute(AContext: TIdContext);
var
   Len,i,ClientPort : Integer;
   Str,HexStr,ClientIP : string;
begin
   Len := AContext.Connection.Socket.InputBuffer.Size;
   Str :=   AContext.Connection.Socket.ReadString(Len);   if Str <>'' then
   begin
     for i := 1 to Length(Str)do
       HexStr := HexStr+' '+IntToHex(Byte(Str[i]),2);     ClientPort := AContext.Connection.Socket.Binding.PeerPort;
     ClientIP    := AContext.Connection.Socket.Binding.PeerIP;     Memo1.Lines.Add('ReadForm:'+ClientIP+'--'+IntToStr(ClientPort)+'--DataLen:'+IntToStr(Len)+'--linkcount:'+IntToStr(GPRSTCPServer.Contexts.LockList.Count));
     Memo1.Lines.Add('ASC:'+Str);
     Memo1.Lines.Add('HEX:'+HexStr);
   end;
end;这个代码发现第一个客户端连接进来后能够正常的接收到数据,第2个客户端连接进来后不能正常接收到第2个客户端的信息。这是什么原因呀?

解决方案 »

  1.   

    就是保持1000个客户端有没有问题?
    第2个:
    我没有特别的设置是哪种模式,indy不是应该都是阻塞模式的吗
      

  2.   

    你在界面上放一个TidAntiFreeze组件试试
      

  3.   

    我把完整代码贴出来你帮我看下吧,有什么问题
    unit GPRSControl;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, ExtCtrls, Buttons, IdContext, IdAntiFreezeBase,
      IdAntiFreeze, IdBaseComponent, IdComponent, IdCustomTCPServer, IdTCPServer,
      IdScheduler, IdSchedulerOfThread, IdSchedulerOfThreadDefault;type
      TForm2 = class(TForm)
        GroupBox1: TGroupBox;
        GroupBox2: TGroupBox;
        Splitter1: TSplitter;
        GroupBox3: TGroupBox;
        Memo1: TMemo;
        SpeedButton1: TSpeedButton;
        GPRSTCPServer: TIdTCPServer;
        IdAntiFreeze1: TIdAntiFreeze;
        Label1: TLabel;
        IdSchedulerOfThreadDefault1: TIdSchedulerOfThreadDefault;
        Button1: TButton;
        SpeedButton2: TSpeedButton;
        procedure SpeedButton1Click(Sender: TObject);
        procedure GPRSTCPServerConnect(AContext: TIdContext);
        procedure GPRSTCPServerExecute(AContext: TIdContext);
        procedure GPRSTCPServerDisconnect(AContext: TIdContext);
        procedure Button1Click(Sender: TObject);
        procedure SpeedButton2Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form2: TForm2;implementation{$R *.dfm}procedure TForm2.GPRSTCPServerConnect(AContext: TIdContext);
    begin
      Memo1.Lines.Add('连入ip'+AContext.Connection.Socket.Binding.PeerIP);
    end;procedure TForm2.GPRSTCPServerDisconnect(AContext: TIdContext);
    begin
      //Label1.Caption := '当前连接数:'+IntToStr(GPRSTCPServer.Contexts.LockList.Count);
    end;procedure TForm2.GPRSTCPServerExecute(AContext: TIdContext);
    var
       Len,i,ClientPort : Integer;
       Str,HexStr,ClientIP : string;
    begin
       Len := AContext.Connection.Socket.InputBuffer.Size;
       Str := AContext.Connection.Socket.ReadString(Len);   if Str <>'' then
       begin
         for i := 1 to Length(Str)do
           HexStr := HexStr+' '+IntToHex(Byte(Str[i]),2);     ClientPort := AContext.Connection.Socket.Binding.PeerPort;
         ClientIP    := AContext.Connection.Socket.Binding.PeerIP;     Memo1.Lines.Add('ReadForm:'+ClientIP+'--'+IntToStr(ClientPort)+'--DataLen:'+IntToStr(Len)+'--'+IntToStr(GPRSTCPServer.Contexts.LockList.Count));
         Memo1.Lines.Add('ASC:'+Str);
         Memo1.Lines.Add('HEX:'+HexStr);
       end;
    end;procedure TForm2.SpeedButton1Click(Sender: TObject);
    begin
       //启动GPRS
       if GPRSTCPServer.Active=false then
       begin
         GPRSTCPServer.Bindings.Clear;
         GPRSTCPServer.Bindings.Add.IP := '127.0.0.1';
         GPRSTCPServer.Bindings.Add.Port := strtoint('6000');
         GPRSTCPServer.Active := true;
       end;end;procedure TForm2.SpeedButton2Click(Sender: TObject);
    var
      Cont:TIdContext;
      i:integer;
    begin
       //关闭GPRS
       if GPRSTCPServer.Active=true then
       begin     for i:=GPRSTCPServer.Contexts.LockList.Count-1 downto 0 do
         begin
              Cont:=TIdContext(GPRSTCPServer.Contexts.LockList.Items[i]);
              Cont.Connection.Disconnect;
         end;
         GPRSTCPServer.Contexts.Clear;
         GPRSTCPServer.Contexts.UnLockList;     GPRSTCPServer.Active:=false;   end;
    end;end.
      

  4.   

      Memo1.Lines.Add('ReadForm:'+ClientIP+'--'+IntToStr(ClientPort)+'--DataLen:'+IntToStr(Len)+'--'+IntToStr(GPRSTCPServer.Contexts.LockList.Count));
      Memo1.Lines.Add('ASC:'+Str);
      Memo1.Lines.Add('HEX:'+HexStr);线程 写 Memo 是不好的习惯。
    用 WriteLn 吧。
    单元头加上 {$APPTYPE CONSOLE}
      

  5.   

    线程里不要访问可视控制,记得要同步,楼上说的没错
    另外INDY10不知道,INDY9不可能支持1000以上连接,3,5百差不多