TLS を使用して小さな「チャット」プログラムをプログラミングしたい
SSL ソケットと入力ストリームに問題があります。TLS 部分は正常に動作します。
私の問題は次のとおりです。 " bufferedreader.ready()
" は常に返されますfalse
。「正常に」動作する場合は -satetmant を削除します。プログラムは、\n または \r が存在するまで待機し、System.out に出力します。しかし、その間メッセージを送ることができません。
"クライアント"
InputStream inputstream = System.in;
InputStreamReader inputstreamreader = new InputStreamReader(inputstream);
BufferedReader bufferedreader = new BufferedReader(inputstreamreader);
InputStream inputstream1 = socket.getInputStream();
InputStreamReader inputstreamreader1 = new InputStreamReader(inputstream1);
BufferedReader bufferedreader1 = new BufferedReader(inputstreamreader1);
OutputStream outputstream = socket.getOutputStream();
OutputStreamWriter outputstreamwriter = new OutputStreamWriter(outputstream);
BufferedWriter bufferedwriter = new BufferedWriter(outputstreamwriter);
OutputStream outputstream1 = System.out;
OutputStreamWriter outputstreamwriter1 = new OutputStreamWriter(outputstream1);
BufferedWriter bufferedwriter1 = new BufferedWriter(outputstreamwriter1);
//Mitteilen, welchen Kommprofil zum verbindugn genutzt werden soll.
bufferedwriter.write("bez\n");
while (true) {
if (bufferedreader.ready()) {
bufferedwriter.write(bufferedreader.readLine() + '\n');
bufferedwriter.flush();
}
if (bufferedreader1.ready()) {
bufferedwriter1.write(bufferedreader1.readLine() + '\n');
bufferedwriter1.flush();
}
}
"サーバ":
InputStream inputstream = sslsocket.getInputStream();
InputStreamReader inputstreamreader = new InputStreamReader(inputstream);
BufferedReader bufferedreader = new BufferedReader(inputstreamreader);
InputStream inputstream1 = System.in;
InputStreamReader inputstreamreader1 = new InputStreamReader(inputstream1);
BufferedReader bufferedreader1 = new BufferedReader(inputstreamreader1);
OutputStream outputstream = System.out;
OutputStreamWriter outputstreamwriter = new OutputStreamWriter(outputstream);
BufferedWriter bufferedwriter = new BufferedWriter(outputstreamwriter);
OutputStream outputstream1 = sslsocket.getOutputStream();
OutputStreamWriter outputstreamwriter1 = new OutputStreamWriter(outputstream1);
BufferedWriter bufferedwriter1 = new BufferedWriter(outputstreamwriter1);
while (true ) {
if (bufferedreader.ready()) {
bufferedwriter.write(bufferedreader.readLine() + '\n');
bufferedwriter.flush();
}
if (bufferedreader1.ready()) {
bufferedwriter1.write(bufferedreader1.readLine() + '\n');
bufferedwriter1.flush();
}
}