#1 2018-08-02 18:13:21

Sapiem
Member
Registered: 2017-12-08
Posts: 62

THttpApiServer doesn't work in netwrok with Win 7

Hello:

I'm trying to connect 3 PC with Win 7 between them. One will have the server and will work as client too like the others.

Trying to use example with THttpApiServer, it work great in Win 10. In the Pc with Server/Client functions, it works ok too, but the others two doesn't see the server.

This is the Server code

procedure TForm16.SetServerBtnClick(Sender: TObject);
begin
  if SetServerBtn.Caption = 'Activar' then
    begin
      FileListBox1.Enabled := false;
      SetServerBtn.Caption := 'Desactivar';
      Props := TSQLDBSQLite3ConnectionProperties.Create(FileListBox1.FileName, '', '', 'password');
      try
        fProps := Props;
        Conn := fProps.ThreadSafeConnection;
        if not Conn.Connected then
          Conn.Connect;
        FServer := THttpApiServer.Create(false);
        FServer.AddUrl('', PortTxt.Text, false, '+', true);
        FServer.RegisterCompress(CompressDeflate);
        FServer.OnRequest := Process;
        FServer.Clone(31);

        try
          Memo1.Lines.Add('Servidor activo en http://' + ServerURLTxt.Text + ':' + PortTxt.Text + '/' + NL +
            'Base de datos disponible: ' + ExpandFileName(UTF8ToString(Props.ServerName)));
        except
          // error
          Memo1.Lines.Add('Ocurrió un error al mostrar datos de conexión.');
          FileListBox1.Enabled := true;
          SetServerBtn.Caption := 'Activar';
        end;
      except
        // error
        Memo1.Lines.Add('Ocurrió un error al intentar conectar.');
        FileListBox1.Enabled := true;
        SetServerBtn.Caption := 'Activar';
      end;

    end
  else
    begin
      FileListBox1.Enabled := true;
      SetServerBtn.Caption := 'Activar';
      FServer.Free;
      Memo1.Lines.Add('Desconectado');
    end;
end;

This is the Client code

function TForm16.BuscarSQL(const SQL: RawUTF8): RawUTF8;
var
  Http: THttpClientSocket;
begin
  Http := OpenHttp(ServerURLTxt.Text, PortTxt.Text);
  if Http <> nil then
    try
      Http.Post('', SQL, TEXT_CONTENT_TYPE);
      Result := Http.Content;
    finally
      Http.Free;
    end
  else
    Result := '';
end;

Locally works great, even using localhost as unique IP.

Last edited by Sapiem (2018-08-02 18:16:23)

Offline

#2 2018-08-02 19:24:22

mpv
Member
From: Ukraine
Registered: 2012-03-24
Posts: 1,544
Website

Re: THttpApiServer doesn't work in netwrok with Win 7

1. Check DNS
2. Check http.sys registration tables

Offline

#3 2018-08-02 19:43:45

Sapiem
Member
Registered: 2017-12-08
Posts: 62

Re: THttpApiServer doesn't work in netwrok with Win 7

This network don't use DNS.
How check http.sys registration tables?

Offline

#4 2018-08-02 20:47:23

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,238
Website

Re: THttpApiServer doesn't work in netwrok with Win 7

3. Ping between the computers
4. Firewall

Offline

#5 2018-08-03 02:23:49

Sapiem
Member
Registered: 2017-12-08
Posts: 62

Re: THttpApiServer doesn't work in netwrok with Win 7

ping works
Firewall are disabled or allowed both app.

Indy10 TidHTTP works ok always.

Any lack in my code?

Offline

#6 2018-08-03 02:46:15

Sapiem
Member
Registered: 2017-12-08
Posts: 62

Re: THttpApiServer doesn't work in netwrok with Win 7

Ok, I check http.sys tables using:

netsh http show urlacl

And it register and then unregister URl using...

procedure TForm16.SetServerBtnClick(Sender: TObject);
begin
  if SetServerBtn.Caption = 'Activar' then
    begin
      FileListBox1.Enabled := false;
      SetServerBtn.Caption := 'Desactivar';
      Props := TSQLDBSQLite3ConnectionProperties.Create(FileListBox1.FileName, '', '', 'password');
      try
        if CheckBox1.Checked then                                                                                      <----- This added
          THttpApiServer.AddUrlAuthorize('MyServerRoot', PortTxt.Text, false, '+');
        fProps := Props;
        Conn := fProps.ThreadSafeConnection;
        if not Conn.Connected then
          Conn.Connect;
        FServer := THttpApiServer.Create(false);
        FServer.AddUrl('MyServerRoot', PortTxt.Text, false, '+', true);
        FServer.RegisterCompress(CompressDeflate);
        FServer.OnRequest := Process;
        FServer.Clone(31);

        try
          Memo1.Lines.Add('Servidor activo en http://' + ServerURLTxt.Text + ':' + PortTxt.Text + '/MyServerRoot/' + NL +
            'Base de datos disponible: ' + ExpandFileName(UTF8ToString(Props.ServerName)));
        except
          // error
          Memo1.Lines.Add('Ocurrió un error al mostrar datos de conexión.');
          FileListBox1.Enabled := true;
          SetServerBtn.Caption := 'Activar';
        end;
      except
        // error
        Memo1.Lines.Add('Ocurrió un error al intentar conectar.');
        FileListBox1.Enabled := true;
        SetServerBtn.Caption := 'Activar';
      end;

    end
  else
    begin
      if CheckBox1.Checked then                                                                                      <----- This added
        THttpApiServer.AddUrlAuthorize('MyServerRoot', PortTxt.Text, false, '+', true);
      FileListBox1.Enabled := true;
      SetServerBtn.Caption := 'Activar';
      FServer.Free;
      Memo1.Lines.Add('Desconectado');
    end;
end;

And neither work....

Last edited by Sapiem (2018-08-07 18:09:35)

Offline

#7 2018-08-03 07:01:31

mpv
Member
From: Ukraine
Registered: 2012-03-24
Posts: 1,544
Website

Re: THttpApiServer doesn't work in netwrok with Win 7

Sometimes urlacl contains several records with conflicts. May be you have IIS apps on this host, or register several urls using mormot. Remove all records about your port, when register to the host name,  not to the +. If indy works, then problem is in http.sys

Offline

#8 2018-08-03 19:17:35

Sapiem
Member
Registered: 2017-12-08
Posts: 62

Re: THttpApiServer doesn't work in netwrok with Win 7

Working behind a proxy can it be related to this problem?

Offline

#9 2018-08-07 01:56:30

Sapiem
Member
Registered: 2017-12-08
Posts: 62

Re: THttpApiServer doesn't work in netwrok with Win 7

Please, any solution? I tried a lot of variant and nothing...

When I run netsh http show urlacl I get this:

    Dirección URL reservada            : http://+:8995/MyServerRoot/
        Usuario: \Everyone
            Escuchar: Yes
            Delegar: Yes
            SDDL: D:(A;;GA;;;WD)

Please.... Why idHTTP runs ok and this not? With idHTTP I can't send to server long params... (SQL commands)

Last edited by Sapiem (2018-08-07 02:35:17)

Offline

#10 2018-08-07 13:48:31

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,238
Website

Re: THttpApiServer doesn't work in netwrok with Win 7

IdHttp is using raw sockets, whereas THttpApiServer uses the http.sys high-performance server included in latest Windows.

For http.sys registration to work, you need to execute the program with administrator rights (root).
Once it is registered, no need to be admin any more.

Offline

#11 2018-08-10 10:30:23

Sapiem
Member
Registered: 2017-12-08
Posts: 62

Re: THttpApiServer doesn't work in netwrok with Win 7

Please, could you try my above code I tell me if it works for you? I did all that all of you said, and nothing.

Offline

#12 2018-08-10 17:37:00

mpv
Member
From: Ukraine
Registered: 2012-03-24
Posts: 1,544
Website

Re: THttpApiServer doesn't work in netwrok with Win 7

Do you have IIS installed? Just create a site in IIS control panel for some static folder. Verify it is work. Then shut down site in IIS and use the same URI for mormot without call to addUrlAuthorise.

Offline

#13 2018-08-11 00:17:10

Sapiem
Member
Registered: 2017-12-08
Posts: 62

Re: THttpApiServer doesn't work in netwrok with Win 7

mpv wrote:

Do you have IIS installed? Just create a site in IIS control panel for some static folder. Verify it is work. Then shut down site in IIS and use the same URI for mormot without call to addUrlAuthorise.

I installed IIS. It works locally, but not with other PC, Smart TV, smartphone, etc.

Xampp works great...

Offline

#14 2018-08-11 15:04:49

mpv
Member
From: Ukraine
Registered: 2012-03-24
Posts: 1,544
Website

Re: THttpApiServer doesn't work in netwrok with Win 7

So, problem not in mormot. Try to ask on IIS or Windows forum

Offline

#15 2018-08-11 22:25:57

Sapiem
Member
Registered: 2017-12-08
Posts: 62

Re: THttpApiServer doesn't work in netwrok with Win 7

mpv wrote:

So, problem not in mormot. Try to ask on IIS or Windows forum

But IIS only works with port 80. mORMot works too with port 80 only, but no bidirectionally, only works reading from PC where IIS is configured (and turned off, of course).

I will ask in other forums. Thanks.

Offline

Board footer

Powered by FluxBB