I cant get this to work, so ill explain what im doing here so you can tell me if im going about this the wrong way.
Client: updateServer()
buf_in = new byte[6000];
buf_out = new byte[6000];
ByteArrayOutputStream byteStreamOut = new ByteArrayOutputStream(6000);
ObjectOutputStream os = new ObjectOutputStream(new BufferedOutputStream(byteStreamOut));
System.out.println("Client is writing to OS...");
os.flush();
os.writeObject(trans_move);
os.writeFloat(x);
os.writeFloat(y);
os.writeInt(world.getMyPlayerID());
os.flush();
System.out.println("Client is finished writing to OS...");
buf_out = byteStreamOut.toByteArray();
packet_out = new DatagramPacket(buf_out, buf_out.length, address, 9991);
sock_out.send(packet_out);
os.close();
Client: receiveUpdate()
buf_in = new byte[6000];
buf_out = new byte[6000];
packet_in = new DatagramPacket(buf_in, buf_in.length);
System.out.println("(receiveUpdate)Client is waiting to recieve...");
multi_socket.receive(packet_in);
ByteArrayInputStream byteStreamIn = new ByteArrayInputStream(buf_in);
ObjectInputStream is = new ObjectInputStream(new BufferedInputStream(byteStreamIn));
System.out.println("(receiveUpdate)Client has recieved packet!");
AffineTransform transMove = (AffineTransform)is.readObject();
float x = (float)is.readFloat();
float y = (float)is.readFloat();
int playerID = (int)is.readInt();
is.close();
The client sends to the server using updateServer(), the server then receives the packet and sends it out to all clients. The client receives the server packets using receiveUpdate().
Ive tried make the server receive and send using the same code as the client uses, and also tried make it simply receive the packet and send it straight back out (without using object input/output at all). I still get the
Exception: java.io.StreamCorruptedException: invalid stream header
java.io.StreamCorruptedException: invalid stream header
at java.io.ObjectInputStream.readStreamHeader(Unknown Source)
at java.io.ObjectInputStream.<init>(Unknown Source)
at Client.receiveUpdate(Client.java:211)
in the clients receiveUpdate() at
ObjectInputStream is = new ObjectInputStream(new BufferedInputStream(byteStreamIn));
Ive spent about 3 weeks on this now and its got to the point where im seriously short on time (its a college project) so all help is appreciated. Thanks.