delphi - Client Application Name in DataSnap -
i have client-server system uses datasnap. want log client application data use tdsserver - onconnect event. in event can access want following code:
ip:= dsconnecteventobject.channelinfo.clientinfo.ipaddress clientport:= dsconnecteventobject.channelinfo.clientinfo.clientport protocol:= dsconnecteventobject.channelinfo.clientinfo.protocol appname:= dsconnecteventobject.channelinfo.clientinfo.appname
first 3 lines ok appname empty!!!
(i run server , client on same computer i.e. localhost)
i have been unable find online information how specify appname when client connects via tcp/ip. if @ code
procedure tdstcpchannel.open; var clientinfo: tdbxclientinfo; begin inherited; freeandnil(fchannelinfo); fchannelinfo := tdbxsocketchannelinfo.create(intptr(fcontext.connection), fcontext.connection.socket.binding.peerip); clientinfo := fchannelinfo.clientinfo; clientinfo.ipaddress := fcontext.connection.socket.binding.peerip; clientinfo.clientport := inttostr(fcontext.connection.socket.binding.peerport); clientinfo.protocol := 'tcp/ip'; fchannelinfo.clientinfo := clientinfo; end;
in datasnap.dstcpservertransport.pas
evident clientinfo.appname not set.
however, following work-around works seattle demo datasnap basic server + client:
in client, add param 'appname' sqlconnection1 component's params , set value 'mytestapp'. recompile client.
open server in ide , modify servercontainerform's code shown below.
code:
uses [...], dbxtransport; procedure tform8.dsserver1connect(dsconnecteventobject: tdsconnecteventobject); var s : string; // added info : tdbxclientinfo; // added begin activeconnections.insert; if dsconnecteventobject.channelinfo <> nil begin activeconnections['id'] := dsconnecteventobject.channelinfo.id; activeconnections['info'] := dsconnecteventobject.channelinfo.info; end; activeconnections['username'] := dsconnecteventobject.connectproperties[tdbxpropertynames.username]; activeconnections['serverconnection'] := dsconnecteventobject.connectproperties[tdbxpropertynames.serverconnection]; activeconnections.post; insertevent('connect'); // following added appname client s := dsconnecteventobject.connectproperties['appname']; info := dsconnecteventobject.channelinfo.clientinfo; info.appname := s; dsconnecteventobject.channelinfo.clientinfo := info; caption := dsconnecteventobject.channelinfo.clientinfo.appname; end;
as can see, works picking value set appname in client's sqlconnection1.params
in call `dsconnecteventobject.connectproperties['appname']' , display on caption of servercontainerform.
obviously, pass other name/value pair adding them sqlconnection's params on client , pick them on server calling dsconnecteventobject.connectproperties[]
.
Comments
Post a Comment