高手:指定idtcpClient的发送端口(100分)

  • 主题发起人 gaoronghui
  • 开始时间
G

gaoronghui

Unregistered / Unconfirmed
GUEST, unregistred user!
由于单位使用防火墙,只能开放指定的端口与外部连接。
所以,在使用idTcpClient与外部的idTcpServer连接时需要
指定某个端口进行发送信息,但是idtcpclient只能指定
server的接收端口:host,port
请问各位高手:能不能在程序启动后指定一个端口给idtcpclient
 
用TClientSocket可以实现,用TIndy没实验过,
http://www.delphibbs.com/delphibbs/dispq.asp?LID=2233463
 
也可以的,
procedure BindIPAndPort(const myip:string; const myport:integer);
var
sockfd: tsocket;
my_addr: sockaddr_in;
begin
// add error checking
sockfd := socket(AF_INET, SOCK_STREAM, 0);
with my_addr do
begin
sin_family := AF_INET; //host byte order
sin_port := htons(myport); // short, network byte order */
sin_addr.s_addr := inet_addr(pchar(myip));
end;
ZeroMemory(@(my_addr.sin_zero), sizeof(my_addr.sin_zero));

//error checking for bind
if bind(sockfd, my_addr, sizeof(sockaddr_in)) = 0 then
showmessage('success')
else showmessage(inttostr(WSAGetLastError));
end;
 
在ClientSocket上测试成功!如果在INDY上也能搞定就好了。[:)]
 

Similar threads

S
回复
0
查看
749
SUNSTONE的Delphi笔记
S
S
回复
0
查看
630
SUNSTONE的Delphi笔记
S
顶部