简体   繁体   中英

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). I also looked for a way to reference the server's connection info to retrieve the client's IP, but without success.

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.

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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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