views:

157

answers:

2

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.

A: 

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

Gonzalo
Port does not seem to be a property of LocalEndPoint.
Matthew
Ah, forgot to cast to IPEndPoint.
Gonzalo
So cast LocalEndPoint as a IPEndPoint and should work ok? I will try :)
Matthew
Hooray. Thankyou very much! The cast worked fine!A++++++++++++++
Matthew
A: 

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.

Matthew