Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Authorization OAUTH2, unknown receiving server port for access token
#1
Hi! I am working on project to send mails using SMTP server and OAUTH2
autorization mechanism with Indy components. There is a moment, when I 
authorizate and it is necessery to open http server to receive the
access token. Before I open the server, it is necessery to know the
default, free, port. It is possible in some situations, that the
previously chosen port can be unavailable in this moment. I am
wondering, if is it possible to set that the server will choose the
first free port or there is no way to do that and I need to know that
the port I set is free? I am the beginner. Thank You for reply.
Reply
#2
Set server port to 0 before starting and it will pick a free available port for you.
Reply
#3
(01-15-2020, 12:38 PM)IndyBeginner Wrote: I am wondering, if is it possible to set that the server will choose the first free port or there is no way to do that and I need to know that the port I set is free?

If the server's Bindings collection is populated before the server is activated, you can set each Binding.Port in the collection as desired.

If the Bindings collection is not populated before activating the server, you can set the server's DefaultPort as desired. When activated, the server will create a default Binding in the collection for you, using the DefaultPort for the Binding.Port.

Setting a given Binding.Port to 0 will let the server ask the OS to pick an available free port for you. Once the server is activated, you can then look at that Binding.Port to see which port it is actually using.

Reply
#4
Thank You, Guys, for Your replies. Both help me a lot. @rlebeau answer works perfect and is straight and easy to understand to me Big Grin
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)