Recent

Author Topic: How to stop a lNet Server listening?  (Read 6293 times)

Niri

  • New member
  • *
  • Posts: 8
How to stop a lNet Server listening?
« on: July 06, 2011, 07:51:37 pm »
Hi,

i have played around a bit with the lNet http server an have managed to extend my monitoring application to send an xml document via http. That works so far.

Because this should be just an additional option the http server should not work all the time but can be switched on and off.

I start listening to incoming connections with the method "listen". But i did not find a method so stop listening. Is there a method and do i simply have overseen it? Or do i have to do another trick to stop the server without stopping the whole application?

Thanks for a hint!
Niri

Niri

  • New member
  • *
  • Posts: 8
Re: How to stop a lNet Server listening?
« Reply #1 on: July 06, 2011, 10:00:27 pm »
OKay, i have tested a little bit and it seems that the disconnect method does what i want. It cuts off the server connection and is able to be reconnected by the listen method used again. I think my confusion was due to the socket also has a disconnect method that is called after each request. But these are obviously different things.

Dibo

  • Hero Member
  • *****
  • Posts: 1048
Re: How to stop a lNet Server listening?
« Reply #2 on: July 07, 2011, 12:10:17 am »
You could create http server in runtime (for example in form create event)
Code: Pascal  [Select][+][-]
  1. type
  2.   TForm1 = class(TForm)
  3.   procedure Form1Create(Sender: TObject);
  4.   private
  5.     FHttpServer: TLHTTPServerComponent;
  6. end;
  7.  
  8. procedure TForm.OnCreate(Sender: TObject);
  9. begin
  10.   FHttpServer := TLHTTPServerComponent.Create(Self);
  11.   FHttpServer.Listen(some_port);
  12. end;
  13.  
And if you want stop listening, just destroy this object calling FHttpServer.Free and recreate if you want listen again

Niri

  • New member
  • *
  • Posts: 8
Re: How to stop a lNet Server listening?
« Reply #3 on: July 08, 2011, 11:28:18 pm »
A good idea, thanks!

 

TinyPortal © 2005-2018