Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: DataSnap, HTTPTransport and port change


This question is answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 5 - Last Post: Nov 6, 2015 1:04 PM Last Post By: Markus Humm
Markus Humm

Posts: 5,113
Registered: 11/9/03
DataSnap, HTTPTransport and port change  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 30, 2015 2:21 AM
Hello,

I'm building a Delphi 10 Seattle DataSnap enabled application using HTTP transport
and I have some issues regarding changing the port to be used at runtime.

I have the RestServerContainer DataModule with a DSServer and DSServerClass
component each and I have 2 TDSHTTPService components.

I want to be able to change the HTTP port at runtime, which I do the following
way but which doesn't change it until I restart my application:

procedure TRemoteServerContainer.Init(OPCActive, OPCHTTPS, WebActive,
  WebHTTPS: Boolean; OPCPort, WebPort: Word; RefreshInterval: UInt32);
begin
  DSServer.Stop;
  OPCRestService.Stop;
  HTTPService.Stop;
 
  OPCRestService.HttpPort := OPCPort;
 
  if OPCHTTPS then
    OPCRestService.CertFiles := DSCertFiles
  else
    OPCRestService.CertFiles := nil;
 
  HTTPService.HttpPort := WebPort;
 
  if WebHTTPS then
    HTTPService.CertFiles := DSCertFiles
  else
    HTTPService.CertFiles := nil;
 
  DSServer.Start;
 
  if OPCActive then
    OPCRestService.Start
  else
    OPCRestService.Stop;
 
  if WebActive then
    HTTPService.Start
  else
    HTTPService.Stop;
end;


When I run netstat -a -b -p TCP I can clearly see that the new port isn't used.
When I restart the application it is used.

Can anybody tell me what I'm doing wrong or why this happens?

Greetings

Markus
Cesar Romero


Posts: 462
Registered: 3/22/00
Re: DataSnap, HTTPTransport and port change  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 3, 2015 5:22 AM   in response to: Markus Humm in response to: Markus Humm
Markus Humm wrote:

Can anybody tell me what I'm doing wrong or why this happens?

I have this working in my projects, this is my code to stop the server
before reconfigure and restart:

procedure TServerContainer.StopHttpServer;
begin
if FServidorHttp.Active then
begin
TerminateThreads;
FServidorHttp.Active := False;
FServidorHttp.Bindings.Clear;
end;
end;

procedure TerminateThreads;
begin
if TDSSessionManager.Instance <> nil then
begin
TDSSessionManager.Instance.TerminateAllSessions;
end;
end;

So, I think you should TerminateAllSessions and call

HTTPService.Bindings.Clear.

[]s

Cesar Romero

Markus Humm

Posts: 5,113
Registered: 11/9/03
Re: DataSnap, HTTPTransport and port change  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 3, 2015 9:33 AM   in response to: Cesar Romero in response to: Cesar Romero
Am 03.11.2015 um 14:22 schrieb Cesar Romero:
Markus Humm wrote:

Can anybody tell me what I'm doing wrong or why this happens?

I have this working in my projects, this is my code to stop the server
before reconfigure and restart:

procedure TServerContainer.StopHttpServer;
begin
if FServidorHttp.Active then
begin
TerminateThreads;
FServidorHttp.Active := False;
FServidorHttp.Bindings.Clear;
end;
end;

procedure TerminateThreads;
begin
if TDSSessionManager.Instance <> nil then
begin
TDSSessionManager.Instance.TerminateAllSessions;
end;
end;

So, I think you should TerminateAllSessions and call

HTTPService.Bindings.Clear.

[]s

Cesar Romero


Hello,

thanks for your information. I really appreciate this and will test it.
It might just take a few days as I'm working in 2 quite different
projects in parallel and I'm currently knee deep in the other one ;-)

Greetings

Markus
Markus Humm

Posts: 5,113
Registered: 11/9/03
Re: DataSnap, HTTPTransport and port change  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 6, 2015 3:12 AM   in response to: Cesar Romero in response to: Cesar Romero
Cesar Romero wrote:
Markus Humm wrote:

Can anybody tell me what I'm doing wrong or why this happens?

I have this working in my projects, this is my code to stop the server
before reconfigure and restart:

procedure TServerContainer.StopHttpServer;
begin
if FServidorHttp.Active then
begin
TerminateThreads;
FServidorHttp.Active := False;
FServidorHttp.Bindings.Clear;
end;
end;

procedure TerminateThreads;
begin
if TDSSessionManager.Instance <> nil then
begin
TDSSessionManager.Instance.TerminateAllSessions;
end;
end;

So, I think you should TerminateAllSessions and call

HTTPService.Bindings.Clear.


Hello,

I was just trying your solution, but I cannot find any .Bindings on any of my services etc.
My service is a TDSHTTPService and I'm using XE8.

Terminate AllSessions alone is not good enough. When the DSServer (TDSServer)
has been stopped the old port is no longer visible via Netstat command and when I start
it again it uses the old port number even if the associated TDSHTTPService has got a new
portnumber assigned already.

I tried to set the .Server property of the HTTPService to nil and then back to the DSServer
instance before starting the DSServer again, but it didn't help.

Any ideas?

Greetings

Markus
Cesar Romero


Posts: 462
Registered: 3/22/00
Re: DataSnap, HTTPTransport and port change  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 6, 2015 5:13 AM   in response to: Markus Humm in response to: Markus Humm
Markus Humm wrote:

I was just trying your solution, but I cannot find any .Bindings on
any of my services etc. My service is a TDSHTTPService and I'm using
XE8.

Terminate AllSessions alone is not good enough. When the DSServer
(TDSServer) has been stopped the old port is no longer visible via
Netstat command and when I start it again it uses the old port number
even if the associated TDSHTTPService has got a new portnumber
assigned already.

I tried to set the .Server property of the HTTPService to nil and
then back to the DSServer instance before starting the DSServer
again, but it didn't help.

I'm using TIdHTTPWebBrokerBridge

FServidorHttp := TIdHTTPWebBrokerBridge.Create(Self);

[]s

Cesar Romero

Markus Humm

Posts: 5,113
Registered: 11/9/03
Re: DataSnap, HTTPTransport and port change  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 6, 2015 1:04 PM   in response to: Cesar Romero in response to: Cesar Romero
Am 06.11.2015 um 14:13 schrieb Cesar Romero:
Markus Humm wrote:

I was just trying your solution, but I cannot find any .Bindings on
any of my services etc. My service is a TDSHTTPService and I'm using
XE8.

Terminate AllSessions alone is not good enough. When the DSServer
(TDSServer) has been stopped the old port is no longer visible via
Netstat command and when I start it again it uses the old port number
even if the associated TDSHTTPService has got a new portnumber
assigned already.

I tried to set the .Server property of the HTTPService to nil and
then back to the DSServer instance before starting the DSServer
again, but it didn't help.

I'm using TIdHTTPWebBrokerBridge

FServidorHttp := TIdHTTPWebBrokerBridge.Create(Self);

[]s

Cesar Romero


Hello,

I don't use that one. I'm doing something more simplistic...

Greetings

Markus
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02