Search code examples
socketsc#-4.0network-programmingnat

Get port of the incoming tcp connection


how could I get the port of the client that is connecting to the c# application?


Solution

  • Assuming you have a System.Net.Sockets.Socket object, Type-cast its RemoteEndPoint property to an IPEndPoint and then read its Port property.