I am trying to derive my own class from the .Net Socket class and have override a few of its members for my own use. I run into a problem with the Accept() function, which returns a Socket. Ideally, I would like to convert the returned Socket to my derived class, although I am not sure if it is possible. Here is an example:
class
Lstn : Socket
{
public Lstn() : base(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
{
}
public void Bind(string host, int port)
{
base.Bind(new IPEndPoint(Dns.GetHostByName(host).AddressList[0], port));
}
new public Socket Accept()
{
return Poll(0, SelectMode.SelectRead) ? base.Accept() : null;
}
}
Basically, I'd like to implement something like a copy constructor that accepts a Socket as an argument like this:
public Lstn(Socket cpySck) : base(cpySck.AddressFamily, cpySck.SocketType, cpySck.ProtocolType)
{
//code to copy cpySck into this instance
}