简体   繁体   中英

How to send an object does not implement Serializable interface in java DatagramSocket

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

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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM