Re: How do I derive a class from Socket class. by Peter
Peter
Sat Oct 06 20:37:56 PDT 2007
Valerie Hough wrote:
> Can someone please show me how to derive my own class from the Socket class?
>
> I want to be able to pass data from the created client socket to the
> AcceptConnection handler in the Socket server class, but the Socket class
> has no available data store that I can use.
Typically this is done by creating some kind of container class that
includes the Socket reference and any associated data. Then you pass an
initialized instance of _that_ as your state parameter for the async
method. The callback method can then get the Socket instance and any
other necessary data from the container class instance.
That said, the Socket class isn't sealed. So deriving a new class from
it is as simple as:
class MySocket : Socket
{
// my specialized data here
}
I don't see the point, but you could certainly do that.
Pete