//抓取服务器 的TIdHTTPServer初始化和侦听函;
1 procedure TMainForm.SetServerHostAndPort; 2 var 3 Binding : TIdSocketHandle; 4 begin 5 idhtpsrvr1.Bindings.Clear; 6 //1.绑定IP地址和端口 7 idhtpsrvr1.DefaultPort := 80; //若有固定绑定端口参数,一定要写这个 8 Binding := idhtpsrvr1.Bindings.Add; 9 Binding.IP := sIP; //本服务的IP 10 Binding.Port := sPort; //本服务的端口 11 end; 12 13 //guoqiang.xu 开启http监听 14 try 15 SetServerHostAndPort; 16 idhtpsrvr1.Active := True; 17 if idhtpsrvr1.Active then 18 LogInfo('监听服务器启动成功!', true) 19 else 20 LogInfo('监听服务器启动失败!', true); 21 except on E : Exception do 22 begin 23 LogInfo('监听服务器启动失败!'+ E.Message, true); 24 end; 25 end; 26 // 27 LogInfo('初始化成功', True);