首先要有 TDSServerModule、 TDSServer、TDSTCPServerTransport;
TDSServerClass、TDataModule;实现上述功能主要控件如下图所示
SysUtils, Classes,
DSTCPServerTransport,
DSHTTPCommon, DSHTTP,
DSServer, DSCommonServer, Provider, IdBaseComponent, IdComponent,
IdTCPConnection, IdTCPClient;
其中IdTCPConnection单元一定要有。
代码如下,//符号包含的是主要实现部分;
procedure TServerContainer1.DSServer1Connect(
DSConnectEventObject: TDSConnectEventObject);
var
ClientConnection: TIdTCPConnection;
begin
//=================================================
if DSConnectEventObject.ChannelInfo <> nil then
begin
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(‘客户端ID号:‘+IntToStr(FormMain.ClientID));
FormMain.bsSkinMemo1.Lines.Add(‘客户端IP号:‘+FormMain.ClientIP);
count:=count+1;
FormMain.StatusBar1.Panels[0].Text:=‘同时在线人数‘+IntToStr(count);
end;
end;
Delphi2010中采用DataSnap的三层网络架构服务器获取客户端ip,端口信息
原文地址:http://blog.csdn.net/singular2611/article/details/45370353