[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Port not used with TcpListener

Posted on 2006-11-15
9
Medium Priority
?
827 Views
Last Modified: 2008-01-09
Hi Experts,

I need to  find a port that is not in use to connect my TcpListener.

Thanks in advance for your help.
0
Comment
Question by:noulouk
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
9 Comments
 
LVL 15

Expert Comment

by:ozymandias
ID: 17951138
Pick a port above 8000 and try to use if.
If its in use you should get an error so try another one.
0
 
LVL 9

Author Comment

by:noulouk
ID: 17951338
OK, what is the maximum localhost port number ?
0
 
LVL 9

Author Comment

by:noulouk
ID: 17951342
An int  number I suppose.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 9

Author Comment

by:noulouk
ID: 17951358
I google a little and find max: 65535

Could you confirm ?
0
 
LVL 15

Assisted Solution

by:ozymandias
ozymandias earned 1000 total points
ID: 17951420
That sounds right.
It is the max value of an unsigned 16 bit int.
0
 
LVL 13

Accepted Solution

by:
AngryBinary earned 1000 total points
ID: 17951515
You should not use any port below 49152 without IANA registration, since all ports below 49152 are considered reserved. Generally, people do it anyway. Ports below 1024 are definitely a no-no, and their use carries a significant chance of port conflict.

Best practices dictate that for a definitely safe port, pick one from 49152-65535 (which is indeed the max, btw), or you can register a port with the IANA [www.iana.org] if you plan to distribute the application for general use.

The application to register can be found at http://www.iana.org/protocols/forms.htm.

Cheers,
--Randall
0
 
LVL 9

Author Comment

by:noulouk
ID: 17954016
In msdn doc, they tell I can use new TcpListener(IPAddress.Any, 0) and a port is automatically assigned : is it the best solution ?

" The TcpListener class provides simple methods that listen for and accept incoming connection requests in blocking synchronous mode. You can use either a TcpClient or a Socket to connect with a TcpListener. Create a TcpListener using an IPEndPoint, a Local IP address and port number, or just a port number. Specify Any for the local IP address and 0 for the local port number if you want the underlying service provider to assign those values for you. If you choose to do this, you can use the LocalEndpoint property to identify the assigned information, after the socket has connected.  "
0
 
LVL 15

Expert Comment

by:ozymandias
ID: 17954052
If you don't care which port you actually end up with then yes.
0
 
LVL 13

Expert Comment

by:AngryBinary
ID: 17961264
That will get you a random port. That is fine for outgoing connections, ie ones that you will instantiate, but if you are setting up a listener, you will either want to specify a particular port so that you can specify in the client application which port to connect to, or need to set up an additional service to make the port number available to the client application some other way.
0

Featured Post

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question