MIDP2.0とCLDC1.1を使用してモバイルデバイスで実行されるTCPクライアントを開発しようとしています。サンプルコードを試していますが、次の問題があります。
(MIDletから)データを読み戻そうとすると、奇妙な例外が発生します。
これは私のコードです:
//Wait for an incoming message
firstByte = in.read();
ByteArrayOutputStream textRecieved = new ByteArrayOutputStream(); //Will be used to hold the data
if (firstByte >= 0 )
{
int messageSize = this.in.available();
//Read the message
while (messageSize > 0)
{
byte[] buffer = new byte[messageSize];
this.in.read(buffer);
textRecieved.write(buffer);
messageSize = this.in.available(); //Just in case the server sent the request in chunks.
System.out.println("Reading...");
}
}
textRecieved.close();
これは私が得る例外です:
java.io.IOException:socket::read中の不明なエラー10053 com.sun.midp.io.j2me.socket.Protocol.read0()で、bci = 0 com.sun.midp.io.j2me.socket.Protocol.nonBufferedRead()で、bci = 12 com.sun.midp.io.BufferedConnectionAdapter.readBytes()で、bci = 36 com.sun.midp.io.BaseInputStream.read()で、bci = 227 com.sun.midp.io.BufferedInputStream.fill()で、bci = 172 com.sun.midp.io.BufferedInputStream.read()で、bci = 16 hello.Client.run22222(Client.java:60)で hello.HelloMIDlet.startApp(HelloMIDlet.java:193)で javax.microedition.midlet.MIDletTunnelImpl.callStartApp()で、bci = 1 com.sun.midp.midlet.MIDletPeer.startApp()で、bci = 7 com.sun.midp.midlet.MIDletStateHandler.startSuite()、bci = 269 com.sun.midp.main.AbstractMIDletSuiteLoader.startSuite()で、bci = 52 com.sun.midp.main.CldcMIDletSuiteLoader.startSuite()で、bci = 8 com.sun.midp.main.AbstractMIDletSuiteLoader.runMIDletSuite()で、bci = 161 com.sun.midp.main.AppIsolateMIDletSuiteLoader.main()で、bci = 26
例外の原因となる行は次のとおりです。
firstByte = in.read();
私は別のスレッドで読んでいます。リクエストを送信し、同じサーバーを使用してそれらを読み取ろうとしたときに、同じエラーが発生しました。サーバーは単純なエコーサーバーであり、複雑なものはありません。
PSコードの記述方法はC#のように見えることは知っていますが、Javaであるため、この方法を読み、従う方が簡単だと思います。
ありがとう。