Project needs, need to write protocol forwarding server, and set-top box communication using UDP protocol
Process:
Receive protocol, resolution----write log-> forwards to the specified device.
Before the study of Netty framework, feel relatively light, it is intended to use this framework to achieve, referring to the official simple write a test case;
The UDP data was not received in the Discovery program.
With tcpdump-x UDP port 7887 Listen to the next packet, the machine is received;
Start looking for problems .....
Bla.. Bla...bla ....
import io.netty.channel.channelhandlercontext;import io.netty.channel.simplechannelinboundhandler; import java.net.datagrampacket;/** * created by konbluesky * date : 15/7/16 Morning 12:37 */public class udpserverhandler extends simplechannelinboundhandler<datagrampacket> { @Override public void channelregistered (CHANNELHANDLERCONTEXT&NBSP;CTX) throws Exception { super.channelregistered (CTX); &NBSP;&NBSP;&NBSP;SYSTEM.OUT.PRINTLN ("Connection creation"); } @Override protected void channelread0 (Channelhandlercontext ctx, datagrampacket &NBSP;MSG) throws exception { ctx.writeandflush ( msg); &NBSP;&NBSP;SYSTEM.OUT.PRINTLN ("Data read"); }}
There is no error in the code, the last line to see the discovery;
Import package is wrong, the import part is just hidden by the IDE .... The problem with this dog's blood. It's so freaking out ... It's still not careful!!!!!!!!
Correct import io.netty.channel.socket.datagrampacket;//error//import java.net.DatagramPacket;
Use netty4.x to write the dog blood problem that the UDP server encounters