相关疑难解决方法(0)

为Netty 4.0增加UDP服务器?

有人可以使用UDP服务器为Netty 4.0引导我吗?我看到很多3.x示例,但即使在netty源示例中也没有4.x的迹象.(注意我对Netty很新)

基本上,它是https://netty.io/Documentation/New+and+Noteworthy#HNewbootstrapAPI的示例,但是对于UDP而言.非常感谢帮助

netty

6
推荐指数
1
解决办法
6629
查看次数

带有 Netty 的多线程 UDP 服务器

我正在尝试用 Netty 实现一个 UDP 服务器。这个想法是只绑定一次(因此只创建一个Channel)。这Channel仅使用一个处理程序进行初始化,该处理程序通过ExecutorService.

@Configuration
public class SpringConfig {

    @Autowired
    private Dispatcher dispatcher;

    private String host;

    private int port;

    @Bean
    public Bootstrap bootstrap() throws Exception {
        Bootstrap bootstrap = new Bootstrap()
            .group(new NioEventLoopGroup(1))
            .channel(NioDatagramChannel.class)
            .option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT)
            .handler(dispatcher);

        ChannelFuture future = bootstrap.bind(host, port).await();
        if(!future.isSuccess())
            throw new Exception(String.format("Fail to bind on [host = %s , port = %d].", host, port), future.cause());

        return bootstrap;
    }
}

@Component
@Sharable
public class Dispatcher extends ChannelInboundHandlerAdapter implements InitializingBean { …
Run Code Online (Sandbox Code Playgroud)

java multithreading udp netty

4
推荐指数
1
解决办法
1835
查看次数

标签 统计

netty ×2

java ×1

multithreading ×1

udp ×1