I'm writing a server which accepts connections with the following line:

TcpClient client = listener.AcceptTcpClient();

Next, I'd like to be to determine the client's IP address.

How can I do this? No relevant property/method in TcpClient exists.

Re: Simple Server Question by Jared

Jared
Mon May 24 14:31:25 CDT 2004

Try
Socket s = tcpClient.Client;
IPEndPoint ep = s.RemoteEndPoint as IPEndPoint;
IPAddress address = ep.Address

--
Jared Parson [MSFT]
jaredpar@online.microsoft.com

This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm

"C# Learner" <csharp@learner.here> wrote in message
news:ugKWXKcQEHA.640@TK2MSFTNGP09.phx.gbl...
> I'm writing a server which accepts connections with the following line:
>
> TcpClient client = listener.AcceptTcpClient();
>
> Next, I'd like to be to determine the client's IP address.
>
> How can I do this? No relevant property/method in TcpClient exists.



Re: Simple Server Question by C#

C#
Mon May 24 14:38:45 CDT 2004

Jared Parsons [MSFT] wrote:

> Try
> Socket s = tcpClient.Client;
> IPEndPoint ep = s.RemoteEndPoint as IPEndPoint;
> IPAddress address = ep.Address

Hi Jared,

'Client' doesn't appear to be a property of 'TcpClient'. What is
'tcpClient' an instance of in the above code?

Thanks.

Re: Simple Server Question by Jared

Jared
Mon May 24 14:47:09 CDT 2004

Sorry. Didn't read the documentation close enough. Apparently the
TcpClient.Client property is protected. You can try sub classing TcpClient
to get to the Client property. Outside of reflection I don't see another
way to get to that property.

--
Jared Parson [MSFT]
jaredpar@online.microsoft.com

This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm

"C# Learner" <csharp@learner.here> wrote in message
news:uMqtpbcQEHA.3012@tk2msftngp13.phx.gbl...
> Jared Parsons [MSFT] wrote:
>
> > Try
> > Socket s = tcpClient.Client;
> > IPEndPoint ep = s.RemoteEndPoint as IPEndPoint;
> > IPAddress address = ep.Address
>
> Hi Jared,
>
> 'Client' doesn't appear to be a property of 'TcpClient'. What is
> 'tcpClient' an instance of in the above code?
>
> Thanks.



Re: Simple Server Question by C#

C#
Mon May 24 15:11:05 CDT 2004

Jared Parsons [MSFT] wrote:

> Sorry. Didn't read the documentation close enough. Apparently the
> TcpClient.Client property is protected. You can try sub classing TcpClient
> to get to the Client property. Outside of reflection I don't see another
> way to get to that property.

Ah... it seems a real nuisance that it's protected.

Re: Simple Server Question by C#

C#
Mon May 24 15:24:29 CDT 2004

Jared Parsons [MSFT] wrote:

> Sorry. Didn't read the documentation close enough. Apparently the
> TcpClient.Client property is protected. You can try sub classing TcpClient
> to get to the Client property. Outside of reflection I don't see another
> way to get to that property.

So I guess it isn't possible to determine the client's IP address when
using TcpListener.AcceptTcpClient(), then...

Re: Simple Server Question by Chris

Chris
Mon May 24 19:53:51 CDT 2004

client.RemoteEndPoint..Address.ToString() should give it to you.

"C# Learner" <csharp@learner.here> wrote in message
news:ugKWXKcQEHA.640@TK2MSFTNGP09.phx.gbl...
> I'm writing a server which accepts connections with the following line:
>
> TcpClient client = listener.AcceptTcpClient();
>
> Next, I'd like to be to determine the client's IP address.
>
> How can I do this? No relevant property/method in TcpClient exists.



Re: Simple Server Question by C#

C#
Mon May 24 19:56:56 CDT 2004

Chris Botha wrote:

> client.RemoteEndPoint..Address.ToString() should give it to you.

Hi,

'TcpClient' doesn't have a property called 'RemoteEndPoint'.

BTW, I'm using 'TcpListener.AcceptSocket()' instead of
'TcpListener.AcceptTcpClient()' now, so my question no longer needs an
answer.

Thanks for the replies.

Re: Simple Server Question by Chad

Chad
Wed May 26 13:43:55 CDT 2004

C# Learner <csharp@learner.here> wrote in news:#HATdNfQEHA.1312
@TK2MSFTNGP12.phx.gbl:
> 'TcpClient' doesn't have a property called 'RemoteEndPoint'.
>
> BTW, I'm using 'TcpListener.AcceptSocket()' instead of
> 'TcpListener.AcceptTcpClient()' now, so my question no longer needs an
> answer.

Indy exposes all this for you. :)

www.indyproject.org

Its free too.


--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programming is an art form that fights back"

Get your ASP.NET in gear with IntraWeb!
http://www.atozed.com/IntraWeb/

Re: Simple Server Question by C#

C#
Thu May 27 00:08:07 CDT 2004

Chad Z. Hower aka Kudzu wrote:

> C# Learner <csharp@learner.here> wrote in news:#HATdNfQEHA.1312
> @TK2MSFTNGP12.phx.gbl:
>
>>'TcpClient' doesn't have a property called 'RemoteEndPoint'.
>>
>>BTW, I'm using 'TcpListener.AcceptSocket()' instead of
>>'TcpListener.AcceptTcpClient()' now, so my question no longer needs an
>>answer.
>
> Indy exposes all this for you. :)
>
> www.indyproject.org
>
> Its free too.

Hi Chad,

Yeah, Indy was the first thing that crossed my mind when I started this
project, but I decided to try using the lower-level .NET sockets for the
learning experience (my HTTP knowledge was a bit stale and re-inventing
the wheel is a good way for me to learn :-).

Cheers.