The controls you need
First of all to have Tdsservermodule, Tdsserver, Tdstcpservertransport;
Tdsserverclass, Tdatamodule; The main controls to implement the above functions are as shown in
The included units include
SysUtils, Classes, DSTCPServerTransport, DSHTTPCommon, DSHTTP, DSServer, DSCommonServer, Provider, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient;
Where the idtcpconnection unit must have.
The code is as follows,//the symbol contains the main implementation part;
Procedure Tservercontainer1.dsserver1connect (dsconnecteventobject:tdsconnecteventobject); Varclientconnection:tidtcpconnection;begin//=================================================if Dsconnecteventobject.channelinfo <> nil thenbegin clientconnection: = Tidtcpconnection ( DSCONNECTEVENTOBJECT.CHANNELINFO.ID); Formmain.clientid: = DSConnectEventObject.ChannelInfo.Id; Formmain.clientip: = ClientConnection.Socket.Binding.PeerIP + ': ' + inttostr ( ClientConnection.Socket.Binding.PeerPort); Formmain.serverip: = ClientConnection.Socket.Binding.IP + ': ' + inttostr (ClientConnection.Socket.Binding.Port); ========================================================= FormMain.bsSkinMemo1.Lines.Clear; FORMMAIN.BSSKINMEMO1.LINES.ADD (' Client ID Number: ' +inttostr (Formmain.clientid)); FORMMAIN.BSSKINMEMO1.LINES.ADD (' Client IP number: ' +formmain.clientip '); count:=count+1; Formmain.statusbar1.panels[0]. text:= ' simultaneous online headcount ' +inttostr (count); end;end;
Delphi2010 with Datasnap three-tier network architecture server for client IP, port information