Re: Remote Port

Giganews Newsgroups
Subject: Re: Remote Port
Posted by:  Remy Lebeau (TeamB) (no.spam@no.spam.com)
Date: Fri, 4 Feb 2005

"Julian Wainwright" <jwa…@iess.co.uk> wrote in message
news:CD268D024577C1E875F5jwa…@iess.co.uk...

> Is there a way to get the RemotePort at SessionStart?

The only place to access the client's Port in regards to sessions is via the
OnCreateSession event.  By the time the OnSessionStart event is triggered,
the client's information has already been copied over to the specified
session object, and the Port is not one of the values that TIdHTTPServer
copies to the session.  So you will have to do it yourself manually by
deriving your own class from TIdHTTPSession and using the OnCreateSession
event to instantiate it.  Then you can assign whatever you want to your
sessions.  For example:

    type
        TMyHTTPSession = class(TIdHTTPSession)
        protected
            FRemotePort: Integer;
        public
            constructor Create(AOwner: TIdHTTPCustomSessionList; const
SessionID, RemoteIP: String; RemotePort: Integer);
            property RemotePort: Integer read FRemotePort;
        end;

    constructor TMyHTTPSession.Create(AOwner: TIdHTTPCustomSessionList;
const SessionID, RemoteIP: String; RemotePort: Integer);
    begin
        FRemotePort := RemotePort;
        inherited CreateInitialized(AOwner, SessionID, RemoteIP);
    end;

    procedure TForm1.IdHTTPServer1CreateSession(ASender: TIdPeerThread; var
VHTTPSession: TIdHTTPSession);
    var
        LBinding: TIdSocketHandle;
    begin
        LBinding := ASender.Connection.Socket.Binding;
        VHTTPSession := TMyHTTPSession.Create(IdHTTPServer1.SessionList;
'SomeUniqueValue', LBinding.PeerIP, LBinding.PeerPort);
    end;

    procedure TForm1.IdHTTPServer1SessionState(Sender: TIdHTTPSession);
    var
        LHost: String;
        LPort: Integer;
    begin
        LHost := Sender.RemoteHost;
        LPort := TMyHTTPSession(Sender).RemotePort;
        //...
    end;

Gambit

Replies

None

In response to

Remote Port posted by Julian Wainwright on Fri, 4 Feb 2005