Use netty4.x to write the dog blood problem that the UDP server encounters

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.