下面是我发现的一些关于“网络”的代码,但我无法让它工作。据我所知,它应该工作。遗憾的是,当我在 OpenSSL 工具包中使用 s_server 时,它没有注册连接。服务器是用 Cpp 编写的,并且运行良好(至少我有那么多)。任何人都可以为我做出适当的更正,将不胜感激。
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 );
}
}