473,387 Members | 1,791 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 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 3822
> 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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Stevey | last post by:
I have the following XML file... <?xml version="1.0"?> <animals> <animal> <name>Tiger</name> <questions> <question index="0">true</question> <question index="1">true</question> </questions>
7
by: nospam | last post by:
Ok, 3rd or is it the 4th time I have asked this question on Partial Types, so, since it seems to me that Partial Types is still in the design or development stages at Microsoft, I am going to ask...
3
by: Ekqvist Marko | last post by:
Hi, I have one Access database table including questions and answers. Now I need to give answer id automatically to questionID column. But I don't know how it is best (fastest) to do? table...
0
by: Tim Mavers | last post by:
I am trying to use the ANTS Profiling service to profile a .NET web app (on my machine). I have XP SP2 with the Firewall turned off (my company's security policy sets this). I have talked to ANTS...
10
by: glenn | last post by:
I am use to programming in php and the way session and post vars are past from fields on one page through to the post page automatically where I can get to their values easily to write to a...
4
by: James Proctor | last post by:
Hi there, im trying to write a application that has some socket stuff in. Ive only don socket stuff in vb 6 before. In .net i was using IPEndPoint and i want to enter an ip address and port like...
1
by: BadOmen | last post by:
Hi, This is used in a FAQ and it works fine wile connecting to my computer but I want to connect to an other... Original code: Code: Private _IpEndPoint As New...
10
by: Rider | last post by:
Hi, simple(?) question about asp.net configuration.. I've installed ASP.NET 2.0 QuickStart Sample successfully. But, When I'm first start application the follow message shown. ========= Server...
53
by: Jeff | last post by:
In the function below, can size ever be 0 (zero)? char *clc_strdup(const char * CLC_RESTRICT s) { size_t size; char *p; clc_assert_not_null(clc_strdup, s); size = strlen(s) + 1;
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.