バッファから文字列を読み込んでサーバーに書き込んでいます。私が抱えている問題は、ソケットを開いたままにしてループを書くと、文字列がサーバーによって受信されないということです。 私はこれを使用する場合:writeBytesを使用したJavaクライアントソケット
try {
Socket send = new Socket("localhost", 1490);
DataOutputStream out = new DataOutputStream(send.getOutputStream());
String message = null;
while ((message = buffer.get()) != null){
out.writeBytes(message);
}
out.close();
send.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
をサーバが文字列を受信しませんが、私はこれを行うと、それが正常に動作:
try {
String message = null;
while ((message = buffer.get()) != null){
Socket send = new Socket("localhost", 1490);
DataOutputStream out = new DataOutputStream(send.getOutputStream());
out.writeBytes(message);
out.close();
send.close();
}
} catch (IOException ex) {
ex.printStackTrace();
}
}
もちろん、私は、開閉維持する必要はありませんしかし、ソケット。何が問題ですか?
はい、私はフラッシュを試みましたが、私はまだ同じ問題があります。バッファは常に文字列を持っているので、ソケットが実際に閉じないとは思わない。しかし、なぜ私のメッセージはまだ届いていないのですか? – user1190650