G
GalfordLiu
Unregistered / Unconfirmed
GUEST, unregistred user!
请教Indy9和Indy10的问题.一个很简单的TCP连接的程序.我用Indy9可以执行成功.换到Indy10以后,相同的写法,却老是连不上Server,变化有这么大么?(50分)<br />请教Indy9和Indy10的问题.
一个很简单的TCP连接的程序.我用Indy9可以执行成功.换到Indy10以后,相同的写法,却老是连不上Server,变化有这么大么?
不知道为什么Indy10老是连接不上,是不是我那里写错了?
代码如下:
/////////////////////////////////////////////////////
indy9 Delphi7的
/////////////////////////////////////////////////////
服务端
放一个ListBox,一个TIdTCPServer,DefaultPort为6666
unit Server;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, IdBaseComponent, IdComponent, IdTCPServer;
type
TfrmServer = class(TForm)
IdTCPServer1: TIdTCPServer;
ListBox1: TListBox;
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure IdTCPServer1Execute(AThread: TIdPeerThread);
private
{ Private declarations }
public
{ Public declarations }
end;
var
frmServer: TfrmServer;
implementation
{$R *.dfm}
procedure TfrmServer.FormCreate(Sender: TObject);
begin
IdTCPServer1.Active:=True;
end;
procedure TfrmServer.FormClose(Sender: TObject; var Action: TCloseAction);
begin
IdTCPServer1.active:=False;
end;
procedure TfrmServer.IdTCPServer1Execute(AThread: TIdPeerThread);
var
LLine:string;
begin
LLine:=AThread.Connection.ReadLn();
ListBox1.Items.Add(LLine);
end;
end.
/////////////////////////////////////////////////////
/////////////////////////////////////////////////////
客户端
放一个Edit,一个Button,一个TIdTCPClient;TIdTCPClient的Host为127.0.0.1,Port为6666
unit Client;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient,
StdCtrls, IdIOHandler, IdIOHandlerStream;
type
TfrmClient = class(TForm)
Edit1: TEdit;
Button1: TButton;
IdTCPClient1: TIdTCPClient;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
frmClient: TfrmClient;
implementation
{$R *.dfm}
procedure TfrmClient.Button1Click(Sender: TObject);
begin
IdTCPClient1.Connect();
if IdTCPClient1.Connected then
begin
IdTCPClient1.WriteLn(Edit1.Text);
end;
IdTCPClient1.Disconnect;
end;
end.
/////////////////////////////////////////////////////
Indy10 Delphi2006的
/////////////////////////////////////////////////////
服务端
放一个ListBox,一个TIdTCPServer,DefaultPort为6666
/////////////////////////////////////////////////////
unit Server;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, IdBaseComponent, IdComponent, IdTCPServer,
IdCustomTCPServer,IdContext;
type
TfrmServer = class(TForm)
IdTCPServer1: TIdTCPServer;
ListBox1: TListBox;
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure IdTCPServer1Execute(AContext: TIdContext);
private
{ Private declarations }
public
{ Public declarations }
end;
var
frmServer: TfrmServer;
implementation
{$R *.dfm}
procedure TfrmServer.FormCreate(Sender: TObject);
begin
IdTCPServer1.Active:=True;
end;
procedure TfrmServer.IdTCPServer1Execute(AContext: TIdContext);
var
LLine:string;
begin
LLine:= AContext.Connection.IOHandler.ReadLn;
ListBox1.Items.Add(LLine);
end;
procedure TfrmServer.FormClose(Sender: TObject; var Action: TCloseAction);
begin
IdTCPServer1.active:=False;
end;
end.
/////////////////////////////////////////////////////
客户端
放一个Edit,一个TIdTCPClient,一个TIdIOHandlerStream,
TIdTCPClient的IOHandler设置为TIdIOHandlerStream,
TIdTCPClient的Host为127.0.0.1,Port为6666
/////////////////////////////////////////////////////
unit Client;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient,
StdCtrls, IdIOHandler, IdIOHandlerStream;
type
TfrmClient = class(TForm)
Edit1: TEdit;
Button1: TButton;
IdTCPClient1: TIdTCPClient;
IdIOHandlerStream1: TIdIOHandlerStream;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
frmClient: TfrmClient;
implementation
{$R *.dfm}
procedure TfrmClient.Button1Click(Sender: TObject);
begin
IdTCPClient1.Connect();
if IdTCPClient1.Connected then
begin
IdTCPClient1.IOHandler.WriteLn(Edit1.Text);
end;
IdTCPClient1.Disconnect;
end;
end.
/////////////////////////////////////////////////////
很简单的TCP连接啊,Indy10总是连接不上.难道Indy10还要做什么特殊的设置么?
一个很简单的TCP连接的程序.我用Indy9可以执行成功.换到Indy10以后,相同的写法,却老是连不上Server,变化有这么大么?
不知道为什么Indy10老是连接不上,是不是我那里写错了?
代码如下:
/////////////////////////////////////////////////////
indy9 Delphi7的
/////////////////////////////////////////////////////
服务端
放一个ListBox,一个TIdTCPServer,DefaultPort为6666
unit Server;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, IdBaseComponent, IdComponent, IdTCPServer;
type
TfrmServer = class(TForm)
IdTCPServer1: TIdTCPServer;
ListBox1: TListBox;
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure IdTCPServer1Execute(AThread: TIdPeerThread);
private
{ Private declarations }
public
{ Public declarations }
end;
var
frmServer: TfrmServer;
implementation
{$R *.dfm}
procedure TfrmServer.FormCreate(Sender: TObject);
begin
IdTCPServer1.Active:=True;
end;
procedure TfrmServer.FormClose(Sender: TObject; var Action: TCloseAction);
begin
IdTCPServer1.active:=False;
end;
procedure TfrmServer.IdTCPServer1Execute(AThread: TIdPeerThread);
var
LLine:string;
begin
LLine:=AThread.Connection.ReadLn();
ListBox1.Items.Add(LLine);
end;
end.
/////////////////////////////////////////////////////
/////////////////////////////////////////////////////
客户端
放一个Edit,一个Button,一个TIdTCPClient;TIdTCPClient的Host为127.0.0.1,Port为6666
unit Client;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient,
StdCtrls, IdIOHandler, IdIOHandlerStream;
type
TfrmClient = class(TForm)
Edit1: TEdit;
Button1: TButton;
IdTCPClient1: TIdTCPClient;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
frmClient: TfrmClient;
implementation
{$R *.dfm}
procedure TfrmClient.Button1Click(Sender: TObject);
begin
IdTCPClient1.Connect();
if IdTCPClient1.Connected then
begin
IdTCPClient1.WriteLn(Edit1.Text);
end;
IdTCPClient1.Disconnect;
end;
end.
/////////////////////////////////////////////////////
Indy10 Delphi2006的
/////////////////////////////////////////////////////
服务端
放一个ListBox,一个TIdTCPServer,DefaultPort为6666
/////////////////////////////////////////////////////
unit Server;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, IdBaseComponent, IdComponent, IdTCPServer,
IdCustomTCPServer,IdContext;
type
TfrmServer = class(TForm)
IdTCPServer1: TIdTCPServer;
ListBox1: TListBox;
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure IdTCPServer1Execute(AContext: TIdContext);
private
{ Private declarations }
public
{ Public declarations }
end;
var
frmServer: TfrmServer;
implementation
{$R *.dfm}
procedure TfrmServer.FormCreate(Sender: TObject);
begin
IdTCPServer1.Active:=True;
end;
procedure TfrmServer.IdTCPServer1Execute(AContext: TIdContext);
var
LLine:string;
begin
LLine:= AContext.Connection.IOHandler.ReadLn;
ListBox1.Items.Add(LLine);
end;
procedure TfrmServer.FormClose(Sender: TObject; var Action: TCloseAction);
begin
IdTCPServer1.active:=False;
end;
end.
/////////////////////////////////////////////////////
客户端
放一个Edit,一个TIdTCPClient,一个TIdIOHandlerStream,
TIdTCPClient的IOHandler设置为TIdIOHandlerStream,
TIdTCPClient的Host为127.0.0.1,Port为6666
/////////////////////////////////////////////////////
unit Client;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient,
StdCtrls, IdIOHandler, IdIOHandlerStream;
type
TfrmClient = class(TForm)
Edit1: TEdit;
Button1: TButton;
IdTCPClient1: TIdTCPClient;
IdIOHandlerStream1: TIdIOHandlerStream;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
frmClient: TfrmClient;
implementation
{$R *.dfm}
procedure TfrmClient.Button1Click(Sender: TObject);
begin
IdTCPClient1.Connect();
if IdTCPClient1.Connected then
begin
IdTCPClient1.IOHandler.WriteLn(Edit1.Text);
end;
IdTCPClient1.Disconnect;
end;
end.
/////////////////////////////////////////////////////
很简单的TCP连接啊,Indy10总是连接不上.难道Indy10还要做什么特殊的设置么?