第一个问题:我用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个客户端的信息。这是什么原因呀?
第二个问题:
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个客户端的信息。这是什么原因呀?
解决方案 »
- 如何判断是哪个进程调用DLL中的函数
- 一个下拉框,点击后弹出来小日历 ,可以选日期,点两头的箭头可以改月份,年份,选好后可以显示日期在下拉框 下拉框可以直接输入日期 这是什么
- 这样的报表用fast report怎么做?高分赠!
- 請zhuhuan大俠現身,或哪位通 ADO JOIN得到的結果多表更新的大俠也進來領分 (我就不相信大家都沒有碰到過這樣的問題)
- installshield6.22中如何使安装包运行启动的画面是自己的图象文件?
- 错误分析
- d7报表,急
- 如何取得汉字的开头字母?
- 高分求购Delphi三层C/S进销存系统
- delphi新人,问个客户端发送图片到用户的问题。
- Delphi缩略图效果!
- 罕见之至的问题,高手来,低手来,你们一起上吧,肯定能解决这个问题的,在线等啊
第2个:
我没有特别的设置是哪种模式,indy不是应该都是阻塞模式的吗
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.
Memo1.Lines.Add('ASC:'+Str);
Memo1.Lines.Add('HEX:'+HexStr);线程 写 Memo 是不好的习惯。
用 WriteLn 吧。
单元头加上 {$APPTYPE CONSOLE}
另外INDY10不知道,INDY9不可能支持1000以上连接,3,5百差不多