Sockets - IPEndpoint Port (Maximum Value)

What is the maximum port value that I can assign to my socket when I bind?

Example:

int port = 0; //How far can i go?
Socket m_mainSocket;
m_mainSocket.Bind(new IPEndPoint(IPAddress.Parse("127.0.0.1"), port))
+3
source share
3 answers

IP port numbers are 16-bit unsigned integers. Therefore, 65535 is the maximum port number you can assign.

The documentation for the designer IPEndPoint indicates what ArgumentOutOfRangeExceptionwill be raised if the port is larger . The documentation for states that "the MaxPort value is set to " (65,535). MaxPortMaxPort0x0000FFFF

+9
source

IPEndpoint MaxPort MinPort - :

MaxPort 0x0000FFFF.

0

To programmatically access the maximum value, you can use IPEndPoint.MaxPort as well as IPEndPoint.MinPort for the minimum value. They are useful for verifying that the port that the user enters is within the correct bounds before actually trying to use it in the connection.

0
source

Source: https://habr.com/ru/post/1758173/


All Articles