Retrieving Remote IP Address from TCP Socket

J

-J

When connecting to a server application via a TCP socket connection, how do I retrieve the IP Address of the client computer that is making the connection.

I create and IPEndPoint for the client, then call the connect using the endpoint.

The server application uses TCPListener to pick up client connections.

At this point I want to store the client's IP Address that is making the connection.

Thanks for the help.

-J

___
Newsgroups brought to you courtesy of www.dotnetjohn.com
 
T

Tom Shelton

When connecting to a server application via a TCP socket connection, how do I retrieve the IP Address of the client computer that is making the connection.

I create and IPEndPoint for the client, then call the connect using the endpoint.

The server application uses TCPListener to pick up client connections.

At this point I want to store the client's IP Address that is making the connection.

Thanks for the help.

-J

___
Newsgroups brought to you courtesy of www.dotnetjohn.com

If your using the TcpClient class for the new connections - you can't,
unless you create your own class that inherits from TcpClient because you
have to access the protected Client property of the TcpClass...

If your using a Socket (TcpListner.AcceptSocket) - then you can use
connections RemoteEndPoint property...

Dim ep as IPEndPoint = DirectCast (clientConnection.RemoteEndPoint,
IPEndPoint)

Dim clientIp As IPAddress = ep.Address
Dim clientPort As Integer = ep.Port

HTH
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top