首页>代码>基于netty开发的在线聊天程序netty-chat>/netty-demo-m/src/main/java/com/example/netty/config/RegisterConfig.java
package com.example.netty.config;
import com.example.netty.handlercfg.NettyChildChannelHandler;
import com.example.netty.udpserver.UdpNettyServer;
import com.example.netty.websocketserver.WebSocketNettyServer;
import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.ChannelHandler;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import javax.annotation.Resource;
@Configuration
public class RegisterConfig{
@Resource(name = "nettyChildChannelHandler")
private NettyChildChannelHandler nettyChildChannelHandler;
@Resource(name = "udpNettyServerHandler")
private ChannelHandler udpNettyServerHandler;
@Value("${netty.websocket.port}")
private int webSocketPort;
@Value("${netty.udp.port}")
private int updPort;
@Value("${netty.udp.host}")
private String udpHost;
@Bean
public WebSocketNettyServer getWebSocketServer() {
WebSocketNettyServer webSocketServer = new WebSocketNettyServer();
webSocketServer.setPort(webSocketPort);
webSocketServer.setChildChannelHandler(nettyChildChannelHandler);
return webSocketServer;
}
@Bean
public UdpNettyServer getUdpSocketServer() {
UdpNettyServer udpNettyServer = new UdpNettyServer();
udpNettyServer.setPort(updPort);
udpNettyServer.setHost(udpHost);
udpNettyServer.setChildChannelHandler(udpNettyServerHandler);
return udpNettyServer;
}
@Bean("bossGroup")
public EventLoopGroup getBossGroup() {
return new NioEventLoopGroup();
}
@Bean("workerGroup")
public EventLoopGroup getWorkerGroup() {
return new NioEventLoopGroup();
}
@Bean
public ServerBootstrap getServerBootstrap(){
return new ServerBootstrap();
}
}
最近下载更多
人间蒸发 LV23
3月12日
charleswang LV7
2024年6月11日
ntboss2002 LV3
2024年5月8日
wanglinddad LV55
2024年4月12日
shuangfu LV25
2023年10月19日
qq1061521319 LV4
2023年9月1日
cto1206 LV3
2023年8月29日
youzitao LV11
2023年4月17日
荣》Cowboy LV12
2023年4月12日
dixiu000 LV4
2023年2月28日
最近浏览更多
dane168 LV10
8月30日
denliv_hui LV14
7月30日
kkkllll LV2
1月9日
微信网友_7298640909209600 LV2
2024年12月22日
chuxue11 LV2
2024年11月18日
yunsgui LV1
2024年6月26日
TY0165 LV20
2024年6月17日
charleswang LV7
2024年6月11日
xiaozhi丶 LV15
2024年6月3日
develop LV10
2024年6月2日

