how to get IPaddress's long value

  • Thread starter Thread starter Ryan Liu
  • Start date Start date
R

Ryan Liu

Hi,

Can someone tell me how to calculate an IPaddress's long value?

I have an application which lisiten on a port using UDP protocol. There
could be multiple client sendind UDP data to it and I am only interested
data from one client, I know that client's IP address in form of 127.0.0.1
etc.

I think I need convert that IP into IPaddress then can compare with
parameter in
UdpServer.Receive(ref remoteIpEndPoint);

Thanks a lot in advance!
Ryan
 
have you check out the IPAdress class in the framework it has a some
functions for manipulating address:

System.IPAddress

Hope this helps

Ollie Riches
 
Use IPAddress.Parse.


public static void Receive(ref IPEndPoint remoteEndPoint) {
IPAddress target = IPAddress.Parse("127.0.0.1");
if (!remoteEndPoint.Address.Equals(target)) {
return;
}
// rest of method here
}


Of course you should cache the target endpoint and not parse it every
time, but the above explains what's needed.

HTH,

Sam
 

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

Back
Top