私のサーバークラスでは、ObjectOutputStreamを介して2D char配列を書き出しており、クライアントはこれをObjectInputStreamで読み取ります。ObjectOutputStream
その後、同じものから同じものに別の2D配列を送信しようとしましたObjectInputStream
が、プログラムがクラッシュします。私の改行は中に残っていると思いますが、ObjectOutputStream
それを取り除く方法がわかりません。、、、してみましinFromServ.read()
た。どれも問題を修正しませんでした=/。どんな助けでもいただければ幸いです!inFromServ.readLine()
inFromServ.flush()
クライアントコード:
ObjectInputStream inFromServ = new ObjectInputStream(socket.getInputStream());
printBoard((char[][])inFromServ.readObject()); //Prints the first 2D char array fine
System.out.println(inFromServ.readObject()); //Reads in a string fine
System.out.println(inFromServ.readObject()); //Reads in another string fine
System.out.println("Your shots board:"); //Writes this out fine
printBoard((char[][])inFromServ.readObject()); //Crashes here
サーバーコード:
ObjectInputStream in = new ObjectInputStream(clients[0].getInputStream());
ObjectOutputStream out=new ObjectOutputStream(clients[0].getOutputStream());
char p1brd[][]=new char[10][10];
char p1shots[][]=new char[10][10];
out.writeObject(p1brd); //Writes out the first board fine
out.writeObject("some string"); //Writes this string fine
out.writeObject("some more string"); //Writes this string fine
out.writeObject(p1shots); //Don't even think it gets here... If i put a thread.sleep(10000) before this line it still crashes instantaneously after writing "some more string"
クライアント側はwhile(true)ループ内にあります。printBoard((char [] [])inFromServ.readObject()); try / catchがそれを取得し、プログラムを停止するまでcatchステートメントを何度も吐き出すのは2回目です。