简体   繁体   English

Datasnap 客户端 IP 内 serverMethod

[英]Datasnap client IP within serverMethod

I'm trying to determine the origin of the client IP within any Tcomponent based method of a VCL forms TCP datasnap server - without any channels (besides from the client having to send it).我正在尝试在 VCL forms TCP datasnap 服务器的任何基于 Tcomponent 的方法中确定客户端 IP 的来源 - 没有任何通道(除了来自客户端发送它)。 I also looked for a way to reference the server's connection info to retrieve the client's IP, but without success.我还寻找一种方法来引用服务器的连接信息来检索客户端的 IP,但没有成功。

Was hoping to see procedure/function work something like the following:希望看到过程/功能的工作方式如下:

procedure TServerMethods1.someTask(userId, taskId :integer; data:string);// can be a function
var
  ip:string;
begin
  ip := (ServerContainer1.TDSServer.GetThreadSession).GetData('RemoteIP');// client IP
  // do stuff..
end;

TIA..蒂亚..

try to use TDSSessionManager.GetThreadSession method instead of ServerContainer1.TDSServer.GetThreadSession.尝试使用 TDSSessionManager.GetThreadSession 方法而不是 ServerContainer1.TDSServer.GetThreadSession。

Based on your original question, and your subequent comments, this should answer your question.根据您最初的问题和随后的评论,这应该可以回答您的问题。

procedure TServerContainer.DSServer1Connect(
  DSConnectEventObject: TDSConnectEventObject);
var
  user, newinfo: String;
  ClientInfo: TdbxClientInfo;
begin

  // note: this procedure gets called immediately AFTER DSAuthenticationManager1UserAuthenticate
  user := TDSSessionManager.GetThreadSession.GetData('User');
  ClientInfo := DSConnectEventObject.ChannelInfo.ClientInfo;
  newinfo := Trim(user) + ' | ' + ClientInfo.IpAddress + ' | ' +
    FormatDateTime('yyyy-mm-dd hh:nn:ss', Now);

end;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM