IP Address's

  • Thread starter Thread starter Guest
  • Start date Start date
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
 
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.
 
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
 
Back
Top