Delphi XE5 Rest Datasnap服务器.获取客户端IP地址 [英] Delphi XE5 Rest Datasnap Server. Getting Client IP Address

查看:433
本文介绍了Delphi XE5 Rest Datasnap服务器.获取客户端IP地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用DSServeronconnect事件以及以下代码来获取客户端的IP地址和其他客户端信息.

I'm trying to get a client's IP address and other client information using DSServer's onconnect event with the following code.

我的问题是每次DSConnectEventObject.ChannelInfo都是nil.此外,我无法解析IP地址.

My problem is that DSConnectEventObject.ChannelInfo is nil every time. Additionally, I can't resolve the IP addresses.

请帮助我.谢谢.

procedure TWebModule1.DSServer1Connect(DSConnectEventObject: TDSConnectEventObject);
var
     ci: TDBXClientInfo;
begin
     ci := DSConnectEventObject.ChannelInfo.ClientInfo;
     AddLog(Format('Client %s Connected IP: %s, Port: %s', 
         [ci.Protocol, ci.IpAddress, ci.ClientPort])
     );
end;

推荐答案

如前所述,这是DataSnap中的错误.在XE2中运行正常,但错误出在XE3和XE5之间.已在质量控制报告#121931和#126164中进行了报告.幸运的是,客户端连接属性在Session对象中可用-参见下文:

As mentioned previously, this is a bug in DataSnap. It was working fine in XE2 but the error came in somewhere between XE3 and XE5. It has been reported in QC reports #121931 and #126164. Luckily, the client connection properties are available in the Session object - see below :

var
  Session: TDSSession;
  Protocol, IpAddress, AppName: string;
begin
  Session := TDSSessionManager.GetThreadSession;
  Protocol := Session.GetData('CommunicationProtocol');
  IpAddress := Session.GetData('RemoteIP');
  AppName := Session.GetData('RemoteAppName');
end;

这篇关于Delphi XE5 Rest Datasnap服务器.获取客户端IP地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆