1

I would like to get the portnumber from a sslstream in C#. When you have TcpClient you can extract this like:

TcpClient client = listener.AcceptTcpClient();
var endpoint = ((IPEndPoint)client.Client.RemoteEndPoint);
  • 1
    [`endpoint.Port`](https://learn.microsoft.com/en-us/dotnet/api/system.net.ipendpoint.port?view=netframework-4.8) – Prix Dec 04 '19 at 12:12
  • Hi, @Ibai. First fo all: I didn't do it (Downvote). Now, i think your answer should be complemented with more information about: Why used `TcpClient` instead of `sslstream`, as the question did. Usually, In SO, answers pass for an adicional process called Review, where members of Stack overflow review it and vote according the answer; Maybe, they made downvotingin at your answer. Check this link about answering questions: https://stackoverflow.com/help/how-to-answer. – Jorge Omar Medra Dec 04 '19 at 19:47

1 Answers1

4

SslStream is a "decorator" around another arbitrary Stream, in this case a NetworkStream. It doesn't expose the inner (tail) stream (well, it does, but InnerStream is protected), and SslStream itself has no concept of a port. Basically: you'll need to get this information separately to wrapping it in the decorator.

Marc Gravell
  • 1,026,079
  • 266
  • 2,566
  • 2,900