关于TIdTCPServer连接的问题,大家帮帮忙,实在没办法了。。。

huaxiaoyu 2009-06-27 10:21:05
小弟使用TIdTCPServer <-> TIdTCPClient 进行网络编程,现在出现这样的问题,服务器绑定后,客户端连接,在本机是可以连接的,但是通过局域网就不能连接,提示连接超时!我的代码是这样的:
服务器端绑定:
procedure TForm1.btn1Click(Sender: TObject);
var
idt : TIdSocketHandle;
begin
idtcpsrvr1.DefaultPort := 4099;
idtcpsrvr1.Bindings.Clear;
idt := idtcpsrvr1.Bindings.Add;
idt.Port := 4099;

idtcpsrvr1.Active := True;
lbl1.Caption := '正在监听...';
end;

客户端是这样连接的:
procedure TForm1.btn3Click(Sender: TObject);
begin
idtcpclnt1.BoundIP := '127.0.0.1';
idtcpclnt1.BoundPort := 4050;

idtcpclnt1.Host := edt1.Text; //其中为服务器IP
idtcpclnt1.Port := StrToInt(edt2.Text); //为服务器绑定端口号4099

try
idtcpclnt1.Connect(5000);
except
on e:Exception do
begin
Application.MessageBox(PChar(e.Message),'title');
Exit;
end
end;
if idtcpclnt1.Connected then
begin
Application.MessageBox('Connect OK','title');
end;
end;

本机就可以连接,但是局域网就是不行,不知道是怎么回事,小弟刚接触delphi,请各位大虾不吝赐教,小弟十分感谢...
...全文
155 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
Winmillion 2009-07-08
  • 打赏
  • 举报
回复
127.0.0.1
测试只能本地上线.
要使用DNS代理.或者用网页IP.TXT更新IP地址.
sczyq 2009-07-08
  • 打赏
  • 举报
回复
procedure TForm1.btn1Click(Sender: TObject);
var
idt : TIdSocketHandle;
begin
idtcpsrvr1.DefaultPort := 4099;
idtcpsrvr1.Bindings.Clear;
idt := idtcpsrvr1.Bindings.Add;
idt.Host := '0.0.0.0'; idt.Port := 4099;

idtcpsrvr1.Active := True;
lbl1.Caption := '正在监听...';
end;

adamsun 2009-07-05
  • 打赏
  • 举报
回复
Specifies the IP address to use for the client.

property BoundIP: string;

Description

BoundIP is a String property that specifies the local IP address to be used for the client connection. BoundIP is used in Connect to indicate the bound IP address for the IOHandlerSocket.ConnectClient method.
--BoundIP用于IOHandlerSocket.ConnectClient方法
ourcsdn 2009-07-03
  • 打赏
  • 举报
回复
BoundIP 一般用于 多地址!
madbo 2009-06-29
  • 打赏
  • 举报
回复
客户端是这样连接的:
procedure TForm1.btn3Click(Sender: TObject);
begin
//这两句注释掉就可以了
//idtcpclnt1.BoundIP := '127.0.0.1';
//idtcpclnt1.BoundPort := 4050;

idtcpclnt1.Host := edt1.Text; //其中为服务器IP
idtcpclnt1.Port := StrToInt(edt2.Text); //为服务器绑定端口号4099

try
idtcpclnt1.Connect(5000);
except
on e:Exception do
begin
Application.MessageBox(PChar(e.Message),'title');
Exit;
end
end;
if idtcpclnt1.Connected then
begin
Application.MessageBox('Connect OK','title');
end;
end;


property BoundIP: string;
客户端使用的IP地址。

property BoundPort: Integer;
当前连接的本地端口号。
shuihan20e 2009-06-29
  • 打赏
  • 举报
回复
IdTcpClient只要指定Host和port就可以了,然后Connect();

不明白再看看indy demo吧

1,593

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 网络通信/分布式开发
社区管理员
  • 网络通信/分布式开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧