On my server class I am writing a 2D char array out through an ObjectOutputStream and the client reads this with an ObjectInputStream. Afterwards I try to send another 2D array through the same ObjectOutputStream to the same ObjectInputStream but the program crashes. I guess my newline is left within the ObjectOutputStream but I am unsure of how to get rid of that. I tried inFromServ.read(), inFromServ.readLine(), inFromServ.flush(). None of which fixed the problem =/. Any help would be appreciated!
Client code:
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
Server code:
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"
The client side is within a while(true) loop. Once the printBoard((char[][])inFromServ.readObject()); is called for the second time my try/catch gets a hold of it and spews out the catch statement over and over until I stop the program.