Matthew
Matthew

Reputation: 217

C# Discover the LocalEndPoint AddressFamily port number

When I establish a tcp connection to a server using the TcpClient class, is there any way to find out the source port of this connection? I am trying to implement the exec protocol and stderr port seems to always be source port + 1.

Upvotes: 0

Views: 1279

Answers (2)

Gonzalo
Gonzalo

Reputation: 21175

Use ((IPEndPoint) tcpClient.Client.LocalEndPoint).Port after establishing the connection.

Upvotes: 2

Matthew
Matthew

Reputation: 217

Solved :)

Client sends TCP port number (decimal ascii, null-terminated) of stderr port. If the first byte is a NULL, then server won't make any stderr connection.

Upvotes: 0

Related Questions