Hi
I've been making a simple game for school, and I've gotten stuck at the network part of it.
The game returns a few different exceptions.
java.io.OptionalDataException
java.io.StreamCorruptedException: invalid type code: F0
The type code isn't allways the same either.
Problem is that neither I or my teacher knows where the problem is, so I thought that I might aswell post the queastion here
That is the code which the exceptions are coming from.Code:public void update(PlayerData data)
{
try
{
outStream.writeObject(data);
outStream.flush();
Object input = inStream.readObject();
if(input instanceof NetworkedEntity)
{
NetworkedEntity netEntity = (NetworkedEntity)input;
Point position = netEntity.entityPosition;
Entity entity = null;
if(netEntity.entityID == 21)
{
entity = new Wall(position, GUI);
}
if(entity != null)
{
GUI.controller.addEntity(entity);
}
}
else if(input instanceof PlayerData)
{
PlayerData enemyData = (PlayerData)(input);
if(!enemyData.getName().equals(GUI.playerName))
{
enemyFarmer.setPosition(enemyData.getPosition());
}
}
}
catch(Exception e)
{
System.out.println("Problem updating to the server:" + e);
e.printStackTrace();
}
}
Both NetworkedEntity and PlayerData are serializable.
And the printStackTrace() points the problem to the readline("Object input = inStream.readObject") and outStream is an ObjectOutputStream and inStream is an ObjectInputStream
Not sure that it matters but those 2 functions are the only ones writing/reading.Code:public void addEntity(Entity entity, int id)
{
NetworkedEntity netEntity = new NetworkedEntity(entity.getPosition(), id, true);
try
{
outStream.writeObject(netEntity);
outStream.flush();
GUI.controller.addEntity(entity);
}
catch(Exception e)
{
System.out.println("Problem syncing new Entities:" + e);
}
}
The program can run for a while without any problem, but after you have called for the addEntity function the game gives some sort of Exception.
Any help would be very usefull!
