我的程序哪里有问题(tcpserver 和 TcpClient) 对于您来说绝对简单-------在线等您 ( 积分: 100 )

  • 主题发起人 主题发起人 qi_jianzhou
  • 开始时间 开始时间
Q

qi_jianzhou

Unregistered / Unconfirmed
GUEST, unregistred user!
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Sockets, StdCtrls;

type
TForm1 = class(TForm)
Memo1: TMemo;
Memo2: TMemo;
Button1: TButton;
TcpClient1: TTcpClient;
TcpServer1: TTcpServer;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure TcpServer1Accept(Sender: TObject;
ClientSocket: TCustomIpClient);
procedure FormCreate(Sender: TObject);
procedure TcpClient1Connect(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
i:integer;
begin

for i:=0 to memo2.Lines.Count-1 do begin
tcpClient1.Sendln(memo2.Lines);
end;
end;

procedure TForm1.TcpServer1Accept(Sender: TObject;
ClientSocket: TCustomIpClient);
var
s:string;
begin
s:=clientSocket.Receiveln;
while s<>'' do begin
memo1.Lines.Add(s);
s:=clientSocket.Receiveln;
end;

end;

procedure TForm1.FormCreate(Sender: TObject);
begin
tcpServer1.Active:=true;
tcpClient1.Active:=true;

//tcpClient1.sen
end;

procedure TForm1.TcpClient1Connect(Sender: TObject);
begin
showmessage('ok');
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
tcpClient1.Connect;
end;

end.

点 连接的按纽就是连不到 tcpServer ,我看了看 demos 里的例子,我不想用线程来做,可是这样又连不到 TcpServer ,大家帮我看看是哪里错了
谢谢了
 
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Sockets, StdCtrls;

type
TForm1 = class(TForm)
Memo1: TMemo;
Memo2: TMemo;
Button1: TButton;
TcpClient1: TTcpClient;
TcpServer1: TTcpServer;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure TcpServer1Accept(Sender: TObject;
ClientSocket: TCustomIpClient);
procedure FormCreate(Sender: TObject);
procedure TcpClient1Connect(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
i:integer;
begin

for i:=0 to memo2.Lines.Count-1 do begin
tcpClient1.Sendln(memo2.Lines);
end;
end;

procedure TForm1.TcpServer1Accept(Sender: TObject;
ClientSocket: TCustomIpClient);
var
s:string;
begin
s:=clientSocket.Receiveln;
while s<>'' do begin
memo1.Lines.Add(s);
s:=clientSocket.Receiveln;
end;

end;

procedure TForm1.FormCreate(Sender: TObject);
begin
tcpServer1.Active:=true;
tcpClient1.Active:=true;

//tcpClient1.sen
end;

procedure TForm1.TcpClient1Connect(Sender: TObject);
begin
showmessage('ok');
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
tcpClient1.Connect;
end;

end.

点 连接的按纽就是连不到 tcpServer ,我看了看 demos 里的例子,我不想用线程来做,可是这样又连不到 TcpServer ,大家帮我看看是哪里错了
谢谢了
 
地址,端口设置好没有啊
 
procedure TForm1.TcpServer1Accept(Sender: TObject;
ClientSocket: TCustomIpClient);
var
s:string;
begin
s:=clientSocket.Receiveln;
memo1.Lines.Add(s);
end;
 
地址,端口都设了,都是本机的
还有
procedure TForm1.TcpClient1Connect(Sender: TObject);
begin
showmessage('ok');
end
当我 用
procedure TForm1.Button2Click(Sender: TObject);
begin
tcpClient1.Connect;
end
时,什么也不显示
 
如果端口和地址都正确的话
在窗体创建时
tcpClient1.Active:=true; //如果没有异常就已经连接上了
tcpClient1.Active:=true;与 tcpClient1.Connect效果相同的
 
可是,像您那的那样我也试了,不行的
可以把我的代码复制运行一下,没有别的,只有 两个 button,两个 memo ,tcpServer,tcpClient
谢谢
是我的系统的原因吗?我的是 xp sp2 ,建议各位高手试试,小弟十分感谢
 
分不够,还可以再加,谢谢了
 
帮帮我吧
 
procedure TForm1.FormCreate(Sender: TObject);
begin
tcpServer1.Active:=true;
tcpClient1.Active:=true;

//tcpClient1.sen
end;
在formshow里可能更好。
 
在fromshow
tcpServer1.open;
tcpClient1.open;
另外就是:单机测试网络要通。既处在一个局域网中。
如果还不行,用控件。
 

Similar threads

I
回复
0
查看
601
import
I
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
后退
顶部