News  [SoftwareSite

Latest News
Older News
RSS Feed
 
Complete Projects
Useful Classes
Top Downloads
Message Board
AllAPI.net
 
Send Comments
Software License
Mentalis.org Buttons
Donate
 
Forums -> Security Library Forum
 
Using SecureSockets as Sockets  
by Beary [beary at 9online dot fr]
posted on 2004/05/20

Hello,

I'd like to use securesockets in a code that use sockets without rewriting everything.
Is there a way to cast a securesocket object to a socket object ?
Because this code doesn't compile :
SecureSocket ss = new SecureSocket(...
Socket s = (Socket) ss;

by Pieter Philippaerts [Pieter at mentalis dot org]
posted on 2004/05/21

We didn't inherit from the Socket class to avoid virtual/non-virtual issues. The methods defined on Socket are all declared as non-virtual, which means that if you would do something like this:

Socket s = new MySocket();
s.Connect();

the runtime calls the Connect method of the Socket class instead of the Connect method of the MySocket class.

To avoid these issues, we decided to not inherit from Socket but provide a drop-in replacement instead. Simply changing your Socket s = new Socket(); calls to SecureSocket s = new SecureSocket(); will work. If you then decide to add SSL/TLS support to your application, you can use the appropriate methods or constructors to establish a secure session.

 

Copyright © 2002-2007, The Mentalis.org Team. All rights reserved.
This site is located at http://www.mentalis.org/
Send comments to the webmaster.