DataSnap WebBroker server

This is the forum for miscellaneous technical/programming questions.

Moderator: 2ffat

DataSnap WebBroker server

Postby Lena » Wed Mar 11, 2015 5:33 am

I am create DataSnap WebBroker server with wizard:
Code: Select all
//---------------------------------------------------------------------------
__fastcall TForm2::TForm2(TComponent* Owner)
   : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm2::ButtonStartClick(TObject *Sender)
{
  StartServer();
}
//---------------------------------------------------------------------------
void TerminateThreads(void)
{
  if (TDSSessionManager::Instance != NULL)
  {
    TDSSessionManager::Instance->TerminateAllSessions();
  }
}
//---------------------------------------------------------------------------
void __fastcall TForm2::ButtonStopClick(TObject *Sender)
{
  TerminateThreads();
  FServer->Active = false;
  FServer->Bindings->Clear();
}
//---------------------------------------------------------------------------
void __fastcall TForm2::ButtonOpenBrowserClick(TObject *Sender)
{

  StartServer();
  String url;
  url.sprintf(L"http://localhost:%s", EditPort->Text.c_str());
  ShellExecuteW(0,
        NULL,
        url.c_str(),
        NULL, NULL, SW_SHOWNOACTIVATE);
}
//---------------------------------------------------------------------------
void __fastcall TForm2::ApplicationEvents1Idle(TObject *Sender, bool &Done)
{
  ButtonStart->Enabled = !FServer->Active;
  ButtonStop->Enabled = FServer->Active;
  EditPort->Enabled = !FServer->Active;
}
//---------------------------------------------------------------------------
void __fastcall TForm2::StartServer()
{
  if (!FServer->Active)
  {
    FServer->Bindings->Clear();
    FServer->Bindings->Add()->Port = 9990; // I add one more port here!!!
    FServer->DefaultPort = 9999;
    FServer->Active = true;
  }
}
//---------------------------------------------------------------------------
void __fastcall TForm2::FormCreate(TObject *Sender)
{
  FServer = new TIdHTTPWebBrokerBridge(this);
}
//---------------------------------------------------------------------------


I want use two port: 9990 and 9999
How to analyze the port? The code below does not work.

Code: Select all
//WebModuleUnit1.cpp
void __fastcall TWebModule1::WebModule1DefaultHandlerAction(TObject *Sender, TWebRequest *Request,
        TWebResponse *Response, bool &Handled)
{
  if(Request->ServerPort == 9999)

  Response->Content =
   "<html>"
   "<head><title>Show WebPage</title></head>"
   "<body>Show WebPage</body>"
   "</html>";

  if(Request->ServerPort == 9990)

  Response->Content =
   "<html>"
   "<head><title>Sent data in database</title></head>"
   "<body>Sent data in database</body>"
   "</html>";

}
Lena
BCBJ Master
BCBJ Master
 
Posts: 567
Joined: Sun Feb 06, 2011 1:28 pm

Re: DataSnap WebBroker server

Postby rlebeau » Wed Mar 11, 2015 4:17 pm

Lena wrote:I want use two port: 9990 and 9999


But you are not creating bindings for both ports, only for 9990. DefaultPort is only used when Bindings->Add() is called, to initialize the Port before you can overwrite it. So you need to Add() a binding for both ports:

Code: Select all
void __fastcall TForm2::StartServer()
{
  if (!FServer->Active)
  {
    FServer->Bindings->Clear();
    FServer->Bindings->Add()->Port = 9990;
    FServer->Bindings->Add()->Port = 9999;
    FServer->Active = true;
  }
}


Lena wrote:How to analyze the port? The code below does not work.


Right now, clients are only able to connect to port 9990, because that is the only binding you created. Thus, the ServerPort can never be 9999. Once you correct your Bindings, clients will be able to connect to either port, and ServerPort will reflect that as expected.
Remy Lebeau (TeamB)
Lebeau Software
User avatar
rlebeau
BCBJ Author
BCBJ Author
 
Posts: 1528
Joined: Wed Jun 01, 2005 3:21 am
Location: California, USA

Re: DataSnap WebBroker server

Postby Lena » Thu Mar 12, 2015 1:29 am

Thank you veru much!
Lena
BCBJ Master
BCBJ Master
 
Posts: 567
Joined: Sun Feb 06, 2011 1:28 pm


Return to Technical

Who is online

Users browsing this forum: No registered users and 6 guests