Re: TcpClient and IP

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Tim Jarvis (tjarvis_at_NoSpamForMe.com)
Date: 03/02/04


Date: Tue, 02 Mar 2004 00:02:08 -0800

user@domain.invalid wrote:

> Hello
> How can i read IP of incoming connection when i have TcpClient for
> that connection ?
>
> Thanx

you can get that from a socket object the RemoteEndPoint propery
returns a IPEndPoint structure you can use.

The slightly trick bit is getting the socket object, there are 2
options..

1./ The TcpClient class has a Socket property, but it is protected, so
you could create a custom class that derives from it.

2./ You can use the TcpListener.AcceptSocket method which returns a
socket. (you can create a network stream from the socket that you can
use to create BinaryReader and binaryWriter objects)

then you simply use the socket i.e.

(IpEndPoint)socket.RemoteEndPoint.Address.ToString();

Hope that Helps.

Regards Tim.



Relevant Pages

  • Re: TcpClient and IP
    ... > How can i read IP of incoming connection when i have TcpClient for ... The slightly trick bit is getting the socket object, ... use to create BinaryReader and binaryWriter objects) ...
    (microsoft.public.dotnet.languages.csharp)
  • RE: Need help using tcpClient and tcpListner
    ... even the connect property of the socket doesn't give current ... > deriving from TcpClient can use this property to get or set this Socket. ... > Public Sub New ... > Dim localhostAddress As IPAddress ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Tcp Socket Close Event
    ... Shutdown | TcpClient Members | Managed Extensions for C++ ... Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows ... SocketExceptionAn error occurred when accessing the socket. ... associated with the TcpClient. ...
    (microsoft.public.dotnet.languages.vb)
  • RE: Why Socket is faster than TcpClient?
    ... I did a little bit testing and benchmarking the socket based communication ... I am using the following loop for TcpClient based communication, ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Existance of networkstream
    ... socket behind the TcpListener from its Server property. ... TcpClient object returned by AccepTcpClient is destroyed right after program ... The NetworkStream object ) keeps a reference ...
    (microsoft.public.dotnet.languages.csharp)