Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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?

Posted

Put this line in the constructor.

ServerHostName = Dns.GetHostName (); 

 

The following lines as global in the class

string ServerHostName ;
private string ServerIPAddr;

 

Put the following lines in the function you want.

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.

Posted

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.

Posted (edited)

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

 


[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.

Edited by Madz

The one and only

Dr. Madz

eee-m@il

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...