eran Posted May 12, 2003 Posted May 12, 2003 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? Quote
*Gurus* divil Posted May 12, 2003 *Gurus* Posted May 12, 2003 Are you trying to get the IP address from an existing endpoint? Can I see some existing code? Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
eran Posted May 12, 2003 Author Posted May 12, 2003 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. Quote
*Gurus* divil Posted May 12, 2003 *Gurus* Posted May 12, 2003 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? Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
eran Posted May 14, 2003 Author Posted May 14, 2003 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. Quote
*Gurus* divil Posted May 14, 2003 *Gurus* Posted May 14, 2003 Yes, but on what class is that property? Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
*Gurus* divil Posted May 14, 2003 *Gurus* Posted May 14, 2003 I think you're misunderstanding here. That class doesn't provide a way to get or set the system ip address - it's just how you specify what ip address to connect to when setting up a socket connection. Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
Madz Posted May 14, 2003 Posted May 14, 2003 (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 May 14, 2003 by Madz Quote The one and only Dr. Madz eee-m@il
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.