471,318 Members | 2,172 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,318 software developers and data experts.

IPEndPoint Question

Hi NG,

what is wrong with the following code?
Sender and Revceiver are of the Type IPEndPoint.

//=================
bool IsEqual = tlg.Receiver.Equals(aTlg.Sender);
if(tlg.Receiver.Address == aTlg.Sender.Address)
{
if(tlg.Receiver.Port == aTlg.Sender.Port)
{
}
}
//=================
I have the situation, where IsEqual is true, but the first if - block is
never entered. Why ist that?
If I look at tlg.Reciever.Address, the debugger shows me the same value as
with aTlg.Sender.Address!

What is it that I miss here?

Thanks for hep and hints.
Rainer
Jan 23 '06 #1
4 3735
> bool IsEqual = tlg.Receiver.Equals(aTlg.Sender);
Performs the checks of the address and port, why do you do it additionaly?

Also IPAddress contains not only address, but also address family.

Try to call
if ( tlg.Receiver.Address.Equals(aTlg.Sender.Address) )
{
...
}

--
Vadym Stetsyak aka Vadmyst
http://vadmyst.blogspot.com

"Rainer Queck" <Ra****@noemail.noemail> wrote in message
news:ue*************@TK2MSFTNGP15.phx.gbl...
Hi NG,

what is wrong with the following code?
Sender and Revceiver are of the Type IPEndPoint.

//=================
bool IsEqual = tlg.Receiver.Equals(aTlg.Sender);
if(tlg.Receiver.Address == aTlg.Sender.Address)
{
if(tlg.Receiver.Port == aTlg.Sender.Port)
{
}
}
//=================
I have the situation, where IsEqual is true, but the first if - block is
never entered. Why ist that?
If I look at tlg.Reciever.Address, the debugger shows me the same value as
with aTlg.Sender.Address!

What is it that I miss here?

Thanks for hep and hints.
Rainer

Jan 23 '06 #2
Hi Vadym,
bool IsEqual = tlg.Receiver.Equals(aTlg.Sender); Performs the checks of the address and port, why do you do it additionaly?

This line was not there from the beginning. I added just for debugging.
The problem is, that the if-block was never entered.
Also IPAddress contains not only address, but also address family. In my case the address family should be identical, since I am using two
instances of the same class, to send UDP telegrams to each other, or not?
Try to call
if ( tlg.Receiver.Address.Equals(aTlg.Sender.Address) )

Actually I am now using :
bool IsEqual = tlg.Receiver.Equals(aTlg.Sender);
if (IsEqual)....
to veryfy whether the the telgram received is a answer to the one sent
befor...

I am still confused, why my if (..) did not work.

Regards
Rainer
Jan 23 '06 #3
IPEndPoint doesn't have "==" operator overriden.
If it is not overriden object references are compared, since you're
comparing 2 different objects their references are also different.

That is for IpEndPoint and IPAddress we need to use Equals method to check
their equality

IPEndPoint ipEndP1 = new IPEndPoint(IPAddress.Parse("192.168.10.73"), 10);
IPEndPoint ipEndP2 = new IPEndPoint(IPAddress.Parse("192.168.10.73"), 10);

if (ipEndP1 == ipEndP2)
Console.WriteLine("Equal with ==");
else if ( ipEndP1.Equals(ipEndP2) )
Console.WriteLine("Equal with Equals method");
else
Console.WriteLine("not equal");

if ( ipEndP1.Address == ipEndP2.Address)
Console.WriteLine("Equal with ==");
else if ( ipEndP1.Address.Equals(ipEndP2.Address) )
Console.WriteLine("Equal with Equals method");
else
Console.WriteLine("not equal");

--
Vadym Stetsyak aka Vadmyst
http://vadmyst.blogspot.com
Jan 23 '06 #4
Hi Vadym,

"Vadym Stetsyak" <va*****@ukr.net> schrieb im Newsbeitrag
news:Oh*************@TK2MSFTNGP15.phx.gbl...
IPEndPoint doesn't have "==" operator overriden.
If it is not overriden object references are compared, since you're
comparing 2 different objects their references are also different.

That is for IpEndPoint and IPAddress we need to use Equals method to check
their equality

Now I see. Thank you for your help!

Regards
Rainer
Jan 23 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Stevey | last post: by
reply views Thread by Tim Mavers | last post: by
10 posts views Thread by glenn | last post: by
4 posts views Thread by James Proctor | last post: by
1 post views Thread by BadOmen | last post: by
53 posts views Thread by Jeff | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.