Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

question about extending the Socket class

Status
Not open for further replies.

netooi25

Programmer
Jul 30, 2004
25
US
Hi, I got the idea I would extend the Socket class
and provide a few more useful methods to it for my
program...

I am having a problem though.

When I call the accept method of the ServerSocket class,
It returns a Socket object instead of the subclass object.

It compiles but this is causing a classcastexception when I try to run it in a test program. Can anyone tell me how I can assign the return value of the ServerSocket's accept method to my subclass of the Socket class? Is this possible.

Sorry I posted this in J2EE forum also but looked like it might belong in here instead

Thanks
 
Take a look at the java.net.SocketImplFactory interface. You need to implement this to return instances of your socket. Set your implementation of SocketImplFactory on the ServerSocket using the setSocketFactory method, and you're away.

Tim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top