Finding the IP address of a socket in .Net CF

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello, folks

I have an application with a TCPListener object in it. When a connection comes in, and I want to accept it, I want to know the IP address of the thing that just connected to me. I can call AcceptSocket, and then I have a new socket object, and then I can get the IP address from that

However, I would prefer to use a TcpClient object instead. In the .Net Compact framework, I can't access the Socket member of the TcpClient object, and I can't find any other method that can get the IP address of the remote endpoint for the TcpClient

It just seems like there ought to be a way. I know how to do it if I resign myself to using the Socket class instead of TcpClient, but I want to take advantage of TcpClient's easier use, if I can

What I would really like is to refuse to Accept connections from any except trusted IP addresses, but that seems impossible. It seems like I have to call AcceptSocket in order to create a Socket, which I can then use to call to get the remote endpoint, and then if I don't like them, I can close the socket.
 
Hi,

Thanks for your post. As I understand, you want to get the IP address from
TcpClient object in .NET CF. Please correct me if there is any
misunderstanding.

In .NET Framework, TcpClient class has a protected property
TcpClient.Client which returns the underlying Socket. We can create a
TcpClient derived class to get IP address from Socket via TcpClient.Client.
However, this property is not supported by .NET CF. I am afraid there is no
good workaround other than calling AcceptSocket to get Socket directly.

Since this issue relates to .NET CF, I believe the following newsgroup is
best suited for such problems.
microsoft.public.dotnet.framework. compactframework

Hope this helps.

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Thanks. That was exactly what I wanted to do. Looks like I have to use Socket instead of TcpClient

(I didn't know there was a newsgroup specifically for the compact framework, because it doesn't seem to be accessible from the web page that I use to access these newsgroups. Maybe I'll see if I can rig up outlook as a newsreader, but I think company policy prohibits it.)
 
Back
Top