Thanks to its unified Transport API, Netty makes writing UDP based applications easy as taking a breath. This allows you to reuse existing ChannelHandlers and other utilities that you have written for other Netty based Applications.

Another limitation is that UDP has no error correction like TCP. In TCP if packets are lost during transmission the peer that sends it will know because the receiver sends an acknowledgement of packets received. Failure to receive an acknowledgement causes the peer to re-sent the same packets again. This is not true for UDP. UDP is more like fire and forget, which means it has no idea if the data sent was received at all.

Also be aware that broadcast messages usually only work in the same network as routers will usually block them.

【13.4 Writing the Broadcaster】
clipboard.png

clipboard.png
So lets recap on Figure 13.3. The LogEventBroadcaster use LogEvent messages and write them via the Channel on the local side. This means all the information is encapsulated in the LogEvent messages. Those messages are then sent trough the ChannelPipeline.

While flowing through the ChannelPipeline the LogEvent messages are encoded to DatagramPacket messages, which finally are broadcasted via UDP to the remote peers.
clipboard.png

LogEventBroadcaster——The Server
clipboard.png
clipboard.png

【13.5 Writing the monitor】
clipboard.png
clipboard.png
clipboard.png
clipboard.png
clipboard.png
clipboard.png

【13.6 Using the LogEventBroadcaster and LogEventMonitor】
You will need to open up two different console windows as both of the Applications will keep running until you stop them via CRTL+C.


bedew
278 声望3 粉丝