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..
CodePudding user response:
try to use TDSSessionManager.GetThreadSession method instead of ServerContainer1.TDSServer.GetThreadSession.
CodePudding user response:
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;