I try to create a java game using multithreading, The game provide multiplayer so I need to create a network to make it provide multiplayer. i finished the game and i try to create the network and i was looking for way to send an objects using this network and i found way that using ByteArrayInputStream, ObjectInputStream to receive the object and ByteArrayOutputStream, ObjectOutputStream to send the object, and i know the object must implement Serializable interface to send and receive it in the network. Now i have a problem i use BufferStrategy and Graphics objects to draw my game but BufferStrategy doesn't implements Serializable interface.. How can I fix this problem ?This is method to render my game and exception i got it
0
votes
It doesn't make sense to try to send either of those objects in the first place. Each user should have his own. What you should be sending is game data, not JDK classes.
- user207421
@user207421 .. I know it doesn't make sense when i send JDK object, but i don't send this object i want to send Game object that include all objects and everything about the game but when i was trying send this object i got that exception, i didn't understand it at first but then i understand that exception mean BufferStrategy object doesn't implement Serializable interface
- Ahmed Mehanna
You could copy the code in your question rather than providing a screenshot of it. The main problem I can see is that you should not serialize the renderer. The renderer should reside only in client.
- Alice Oualouest
1 Answers
0
votes
To solve that problem I put transient before any object instance of JDK classes and the class doesn't implement Serializable interface.
code to explain how to use it.
Those are objects before put transient
private BufferStrategy bs;
private Graphics g;
And those are objects after put transient
private transient BufferStrategy bs;
private transient Graphics g;