0
我需要能夠綁定和偵聽端口,並且能夠發送數據包到其他地址,是否可以使用已創建的DatagramChannelFactory
或ConnectionlessBootstrap
來做到這一點?看作UDP是無連接的。netty udp,綁定併發送到其他地址
public static void start() {
DatagramChannelFactory f = new NioDatagramChannelFactory(Executors.newCachedThreadPool());
ConnectionlessBootstrap b = new ConnectionlessBootstrap(f);
b.setPipelineFactory(new ChannelPipelineFactory() {
@Override
public ChannelPipeline getPipeline() throws Exception {
return Channels.pipeline(new Encoder(), new Decoder(), new ServerHandler());
}
});
b.bind(new InetSocketAddress(Config.PORT));
}