简体   繁体   中英

Send JPanel through Java UDP Networking

I have a very basic video game written in Java where all the graphics are displayed in a JPanel . I wish to use UDP Networking to implement a multiplayer feature to this game. To do, one of the basic things I need to be able to do is to send and receive a JPanel with the correct graphics between a client and server using UDP.

I have looked through other questions and tutorials using Java UDP Networking to get an idea of how UDP works, but I am still not quite sure how I would implement a program that sends a JPanel with the proper graphics inside it from client to server and vice versa using UDP?

Is there any advice that someone could give me? Maybe there is a question incredibly similar to this that I just missed when researching?

Thank you!

To do, one of the basic things I need to be able to do is to send and receive a JPanel with the correct graphics between a client and server using UDP.

This is exactly what I recommend that you don't do. Instead, I strongly urge you to send model state, not view display, over your network, and then allow each site to use the model state to construct its own view. Doing it this way will be much more efficient as you'd be sending a much smaller dataset online. But note that if you do this, then you might need to use a more reliable transmission protocol than UDP such as TCP (although not necessarily).

Whether you send the data through UDP or TCP will depend on which is more critical for your game: network speed or absolute data integrity. The network communication is usually the tightest bottleneck. Your desire to send a serialized JPanel means that you'd be sending thousands of data bits over the network where only a few bits are needed.

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