简体   繁体   English

基于Java优先级的udp协议

[英]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. 您似乎在问是否可以用仅使用UDP实现的消息替换消息的TCP字节流和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. TCP是一种可靠的字节流协议,它通过跟踪已发送的内容和已确认的内容在不可靠的IP数据包层之上实现。 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. TCP还实现流控制,以使协议不会使网络过载。

By contrast, UDP does not provide either reliability or flow control. 相反,UDP不提供可靠性或流控制。

It would be possible to implement TCP-like reliability and flow control over any unreliable packet layer ... including UDP/IP. 在包括UDP / IP在内的任何不可靠的数据包层上实现类似于TCP的可靠性和流量控制。 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. 但是,要在Java中做到这一点,您需要在客户端和服务器端的“用户空间”应用程序库中实现类似TCP的协议。 That is a lot of work, and the performance would inevitably be inferior to a real TCP/IP implementation in the OS kernel. 这是很多工作,并且性能不可避免地会劣于OS内核中的实际TCP / IP实现。

Besides, while you are eliminating TCP/IP sockets, you are replacing them with equivalent data structures and buffering in the Java application itself. 此外,在消除TCP / IP套接字的同时,您将它们替换为等效的数据结构并在Java应用程序本身中进行缓冲。 In practice, this is unlikely to save resources on either server or client side. 实际上,这不太可能节省服务器或客户端的资源。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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