"IPEndPoint"(C#)

Eran

Member
Joined
Apr 12, 2003
Messages
69
Hi,

Can any one explain me how to use the "IPEndPoint" Class?
In the MSDN, I get the following results for "IPEndPoint":

"public IPAddress Address {get; set;}
Gets or sets the IP address of the endpoint

"
How do I get the IP of the endpoint using that method?
 
Are you trying to get the IP address from an existing endpoint? Can I see some existing code?
 
Put this line in the constructor.
Code:
ServerHostName = Dns.GetHostName ();

The following lines as global in the class
Code:
string ServerHostName ;
private string ServerIPAddr;

Put the following lines in the function you want.
Code:
IPHostEntry ipE = Dns.GetHostByName (ServerHostName); 
IPAddress [] addr = ipE.AddressList; 
for(int i= 0; i < addr.Length ; i++) 
{
    ServerIPAddr += addr[i].ToString(); 
}

This was one way to obtain IPADDRESS. I wanted to try the other method.
 
The IPEndPoint class represents a combination of an IP address and port. You use it to specify those when connecting to something. How is it you want to use it?
 
Well, according to Microsoft, the following method:
"public IPAddress Address {get; set;}"
gets or sets an IPaddress.

I just wanted to know how to set or get the IPaddress using this method.
 
I think youre misunderstanding here. That class doesnt provide a way to get or set the system ip address - its just how you specify what ip address to connect to when setting up a socket connection.
 
I hope this might help you in understanding IPENDPoint.

IPENDPOINT Represents a network endpoint as an IP address and a port number it is used by SOCKET

Code:
[COLOR=green]// here you are get IP address of some server[/COLOR] 

IPAddress hostadd = Dns.Resolve(some server).AddressList[0];

[COLOR=green]// here you are initializing a new IPENDPOINT by telling it a complete target. 
//such as a server and its port[/COLOR]

IPEndPoint EPhost = new IPEndPoint(hostadd, 80);

[COLOR=green]// here you are definiing a new SOCKET which will use this end point to connect
// to target Host.[/COLOR]

Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Stream,
       ProtocolType.Tcp );
 
[COLOR=green]// Connects to the host using IPEndPoint.[/COLOR]
    s.Connect(EPhost);

I hope now you would have clear understanding about IPEndPoint.
 
Last edited by a moderator:

Similar threads

P
Replies
0
Views
176
Policy standard local admin account with Active Di
P
M
Replies
0
Views
145
MyCatAlex
M
J
Replies
0
Views
59
Jalil Sear [MCPD SharePoint]
J
Back
Top