I am making a chess game application for a practice and finished up all the functionalities.
Now I am trying to implement the networking part so to enable 2 players mode...
In my server code I am using a loop to continuously get the data from both player turn by turn.
At the first turn of each player, the server works just fine and I confirmed the data is transferred correctly to the other player. But when it goes back
to int[] data1 = (int[]) in1.readUnshared();
this very first line of the loop,
java.io.EOFException
at java.io.ObjectInputStream$BlockDataInputStream.peekByte(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.readObject(Unknown Source)
the error occurs...
while(true){
int[] data1 = (int[]) in1.readUnshared(); // THIS PART!!
if(data1.length != 96)
break;
out2.writeUnshared(data1);
out2.flush();
int[] data2 = (int[]) in2.readUnshared();
if(data1.length != 96)
break;
out1.writeUnshared(data2);
out1.flush();
}
Here, "in" and "out" variables are class variables I declared
static ObjectInputStream in1;
static ObjectInputStream in2;
static ObjectOutputStream out1;
static ObjectOutputStream out2;
and I initilized them on the main function like this :
in1 = new ObjectInputStream(player1.getInputStream());
Is there any problem with the way I initialized streams...? been stuck for this problem for quite long... and desperate to see my application working.