IP Address's

G

Guest

Is there any way to resolve the ip address of the host machine or a machine
at the other end of a network connection? I have created a client-server Tcp
project that only uses the TcpClient and TcpListener classes for the
connections.
I have tried:
Dns.Resolve("localhost").Address[0].ToString();
but that only gives me "127.0.0.1"
I would prefer it though if I could resolve the address of the clients from
the server, rather than having to pass the IpAddress across the network.
Any ideas?
Thanks
 
D

Dmitriy Lapshin [C# / .NET MVP]

Hi,

It depends on how you accept incoming TCP connections in the TcpListener. If
you use AcceptSocket, it will return you a Socket instance which you can
query for RemoteEndPoint property.
If you however use AcceptTcpClient, you will have to create a derived class
to access the protected TcpClient's Socket property.
 
G

Guest

I am using the AcceptTcpClient, how would I go about creating a derived class
to access the property?

Dmitriy Lapshin said:
Hi,

It depends on how you accept incoming TCP connections in the TcpListener. If
you use AcceptSocket, it will return you a Socket instance which you can
query for RemoteEndPoint property.
If you however use AcceptTcpClient, you will have to create a derived class
to access the protected TcpClient's Socket property.

--
Sincerely,
Dmitriy Lapshin [C# / .NET MVP]
Bring the power of unit testing to the VS .NET IDE today!
http://www.x-unity.net/teststudio.aspx

R2D2 said:
Is there any way to resolve the ip address of the host machine or a
machine
at the other end of a network connection? I have created a client-server
Tcp
project that only uses the TcpClient and TcpListener classes for the
connections.
I have tried:
Dns.Resolve("localhost").Address[0].ToString();
but that only gives me "127.0.0.1"
I would prefer it though if I could resolve the address of the clients
from
the server, rather than having to pass the IpAddress across the network.
Any ideas?
Thanks
 

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