tags:

views:

118

answers:

3

There is an error showing at this line on execution:

((IPEndPoint)(TcpClient.Client.RemoteEndPoint)).Address;

the eroor is:

An object reference is required for the nonstatic field, method, or property
System.Net.Sockets.TcpClient.Client.get  ...

What is solution for this error?

The code is shown below.

//Assume myList is an ArrayList
IPAddress tempAddress = ((IPEndPoint)(TcpClient.Client.RemoteEndPoint)).Address;
myList.Add(tempAddress);
A: 

do you have an instance of TcpClient ?

Rony
sorry i didn't get it.
Dilse Naaz
A: 

As the compiler error states you need an instance of IPEndPoint to access the Address property.

TcpClient tcpClient = new TcpClient();
IPAddress ipAddress = Dns.GetHostEntry ("www.contoso.com").AddressList[0];
IPEndPoint ipEndPoint = new IPEndPoint (ipAddress, 11004);
IPAddress tempAddress = ipEndPoint.Address;
myList.Add(tempAddress);
Darin Dimitrov
+1  A: 

The error happens because the property RemoteEndPoint is an instance member of TCPClient. This means that you must instantiate a TCPClient (you must "new it") before you can access the RemoteEndPoint.

If you want more help, you need to post the preceeding lines of code so that we can see what you are trying to do.

Tormod
i solved the above problem, but got the new one, that is shown here."Object reference not set to an instance of an object. " This error showing at this line IPAddress ipAddress = ((IPEndPoint)(tClient.Client.RemoteEndPoint)).Address;
Dilse Naaz