How to get the port number when its 0?

  • Thread starter Thread starter Leon_Amirreza
  • Start date Start date
L

Leon_Amirreza

I have created a TcpServerChannel with port number 0 and registered it
now I want the server to write its port number used on screen (host is a
console App)!
How can I do that?
 
I have created a TcpServerChannel with port number 0 and registered it
now I want the server to write its port number used on screen (host isa
console App)!
How can I do that?

Hah! That's a lot harder question than it first appears. :)

Anyway, I was curious, because I had never heard of the TcpServerChannel
object in the first place. I assumed that it'd have some sort of EndPoint
property that would return the assigned address. But alas, that wasn't
the case.

This is a wild guess -- I don't have any code that uses a TcpServerChannel
so I can't really test this theory -- but reading the docs it looks to me
like this might work (C#):

int PortFromChannel(TcpServerChannel channel)
{
ChannelDataStore store = (ChannelDataStore)channel.ChannelData;

return store["port"];
}

Pete
 
Back
Top