C# TCP サーバーからのメッセージを継続的にリッスンする必要があるため、別のスレッドで行います。
private void StartMessageReceivingLoop()
{
new Thread(){
public void run()
{
String msg = null;
try
{
msg = inputStream.readLine(); // inputStream is a BufferedReader instance.
}
catch (IOException e)
{
e.printStackTrace();
}
if (msg != null && msg != "")
NotifyAndForwardMessage(msg); // Notify listeners about the message.
run(); // Next iteration.
}
}.start();
}
私のアプローチの何が問題になっていますか?StackOverflowError が発生するのはなぜですか? run()
非ブロッキングであるため、非常に高速に呼び出されるBufferedReader.readLine()
と思いますが、どうすればよいですか?