Server:
Code:
SSLServerSocketFactory ssocketFactory = (SSLServerSocketFactory) SSLServerSocketFactory.getDefault();
try {
SSLServerSocket ssocket = (SSLServerSocket) ssocketFactory.createServerSocket(PORT);
running = true;
while (running) {
clientSock = ssocket.accept();
// Start create my client object and start() it.
}
} catch (IOException ex) {
Logger.getLogger(main.class.getName()).log(Level.SEVERE, null, ex);
running = false;
}
Client:
Code:
sc = (SecureConnection) Connector.open("ssl://localhost:5555");
SecurityInfo info = sc.getSecurityInfo();
System.out.println("Suite " + info.getCipherSuite() + "\nCertificate: " + info.getServerCertificate() + "\nProtocol " + info.getProtocolName());
DataInputStream reader = sc.openDataInputStream();
writer = sc.openDataOutputStream();
// create my listener class
System.out.println("Connection established on MIDP");
It's basically your standard setup for connecting but it's the certificates that matter.
Make sure you tell your server to use the keystore where you have imported the certificate with the following command flags:
-Djavax.net.ssl.keyStore=SecIM_keystore.jks -Djavax.net.ssl.keyStorePassword=yourPass
You should also use the mekeytool.exe in your J2ME SDK to import the certificate into the emulator. If you're using J2ME SDK 3 then you may be better off using the GUI.
REMEMBER: FILL IN ALL FIELDS ON YOUR CERTIFICATE WHEN YOU CREATE IT
(that's if you create your own)
Vladimir