using protected methods in compact framework

G

Guest

I have managed to use the protected methods in the .net framework.. however i
need to use the protected method ".Client". so as to get the local endpoint
of the current connected socket.

this is the code

public class MyderivedTcpClient : TcpClient
{
// Constructor for the derived class.
public MyderivedTcpClient() : base ()
{
}

public String getAddress()
{
// Calls the protected 'Client' property belonging to the TcpClient base
class.
Socket s = this.Client;
return ((IPEndPoint)s.LocalEndPoint).ToString();
}

}

What solution could you suggest??

Thanks and regards

Thomas Engerer
 
S

Sergey Bogdanov

Well, Client is a private property and can not be accessed from derived
class. However, you can use reflection to achieve what you want:

System.Reflection.FieldInfo fi = typeof(TcpClient).GetField("Client",
System.Reflection.BindingFlags.NonPublic |
System.Reflection.BindingFlags.Instance);
Socket s = (Socket)fi.GetValue(this);
return ((IPEndPoint)s.LocalEndPoint).ToString();

Best regards,
Sergey Bogdanov
http://www.sergeybogdanov.com
 
G

Guest

For some reason when i tried using derived classes on the .net compact
framework it crashes..
is der a reason for this? no exception has come up or anything its simply
crashes when it tries to connect.

Thanks and regards

Thomas Engerer
 
G

Guest

Ok i found the mistake.. however using ure method described below the port
used does not match the actual port being used to communicate..

Any reason y?

Thanks a real lot

Thomas Engerer
 

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

Top