CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Jun 2002
    Posts
    5

    Question Getting Socket Port Numbers

    I have an application that I am converting from Java, and one of the things that the application must do is to read the port number for a socket (client or server). I have been all through the documentation for Socket and TcpListener, but I cannot find a property or method that will give me the port number. The specific Java code I am trying to implement in C# is:

    if ( null != this.client_Socket )
    {
    iPort = this.client_Socket.getPort();
    }
    else if ( null != this.server_Socket )
    {
    iPort = this.server_Socket.getLocalPort();
    }

    Does anyone know how I can get the port numbers?

  2. #2
    Join Date
    Oct 2001
    Location
    Norway
    Posts
    265
    Something like this(not tested):
    Code:
    IPEndPoint endp =(IPEndpoint)this.clientSocket.LocalEndpoint;
    iPort = endp.Port;

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured