简体   繁体   中英

Java priority based udp protocol

我尝试开发简单的mmorpg,由于要发送的数据有2个优先级,一个是必须从服务器发送的基于TCP的信息,另一个是基于UDP的,因为字符移动有一种方法可以将UDP协议设置为能否根据包优先级作为TCP工作?因此,无需打开从服务器到客户端的2个连接。

You seem to be asking if it is possible to replace a TCP bytestream and a UDP "stream" of messages with something implemented just using UDP.

The answer is: "Yes in theory, but in practice it would be a lot of work, would perform poorly, and would achieve very little".

TCP is a reliable byte stream protocol that is implemented on top of an unreliable IP packet layer by keeping track of what has been sent and what has been acknowledged. If specific packets get lost / dropped by the network, the sender or receiver notice and the missing data gets retransmitted. TCP also implements flow control so that the protocol does not overload the network.

By contrast, UDP does not provide either reliability or flow control.

It would be possible to implement TCP-like reliability and flow control over any unreliable packet layer ... including UDP/IP. However, to do this in Java, you would need to implement a TCP-like protocol in a "user-space" application library on both the client and server sides. That is a lot of work, and the performance would inevitably be inferior to a real TCP/IP implementation in the OS kernel.

Besides, while you are eliminating TCP/IP sockets, you are replacing them with equivalent data structures and buffering in the Java application itself. In practice, this is unlikely to save resources on either server or client side.

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