Reputation: 321
Below is some code I found about the 'net and I can't get it working. As far as I know it should work. Sadly, when I used s_server in the OpenSSL toolkit it didn't register a connection. The server is written in Cpp and is working perfectly (at least I have that much). Can anyone make the proper corrections for me it would be greatly appreciated.
import javax.net.ssl.SSLSocket;
import javax.net.ssl.SSLSocketFactory;
import java.io.*;
import java.applet.*;
import java.awt.*;
public class jclientssl extends Applet {
public static void main() {
try {
SSLSocketFactory sslsocketfactory = (SSLSocketFactory) SSLSocketFactory.getDefault();
SSLSocket sslsocket = (SSLSocket) sslsocketfactory.createSocket("localhost", 9999);
InputStream inputstream = System.in;
InputStreamReader inputstreamreader = new InputStreamReader(inputstream);
BufferedReader bufferedreader = new BufferedReader(inputstreamreader);
OutputStream outputstream = sslsocket.getOutputStream();
OutputStreamWriter outputstreamwriter = new OutputStreamWriter(outputstream);
BufferedWriter bufferedwriter = new BufferedWriter(outputstreamwriter);
String string = null;
while ((string = bufferedreader.readLine()) != null) {
bufferedwriter.write(string + '\n');
bufferedwriter.flush();
}
} catch (Exception exception) {
exception.printStackTrace();
}
}
public void paint(Graphics g) {
g.drawString("Welcome to Java!!", 50, 60 );
}
}
Upvotes: 1
Views: 587
Reputation: 53694
If you are running this code as a Applet, then the main method is irrelevant, so your socket code is not being executed. (and, if you want to use that main method in a standalone application, then it needs to be public static void main(String[])
).
Upvotes: 2