Netty怎么用WireShark抓包呢?
这是启动的代码
@ServiceScan
public class Server {
public static void main(String[] args) {
try {
NettyServer nettyServer = new NettyServer("192.168.10.1", 8085, SerializerCode.HESSIAN.getCode());
nettyServer.start();
} catch (RpcException e) {
e.printStackTrace();
}
}
}
@Slf4j
public class NettyServer extends AbstractRpcServer {
/**
* 服务器启动时 优先做一些预加载
*/
/**
*
* @param hostName 启动服务所在机器的主机号,可以是私网或者公网
* @param port 启动服务所在机器的端口号
* @param serializerCode 序列化代码
* @throws RpcException
*/
public NettyServer(String hostName, int port, Integer serializerCode) throws RpcException {
this.hostName = hostName.equals("localhost") || hostName.equals("127.0.0.1") ? IpUtils.getPubIpAddr() : hostName;
log.info("start with host: {}, port: {}", this.hostName, port);
this.port = port;
//serviceRegistry = new NacosServiceRegistry();
//serviceProvider = new DefaultServiceProvider();
/**
* 使用 SPI 机制,接口与实现类解耦到配置文件
*/
serviceRegistry = ServiceLoader.load(ServiceRegistry.class).iterator().next();
serviceProvider = ServiceLoader.load(ServiceProvider.class).iterator().next();
serializer = CommonSerializer.getByCode(serializerCode);
// 扫描 @ServiceScan 包下的 所有 @Service类,并 注册它们
scanServices();
}
@Override
public void start() {
/**
* 封装了 之前 使用的 线程吃 和 任务队列
* 实现了 ExecutorService 接口
*/
ShutdownHook.getShutdownHook().addClearAllHook();
EventLoopGroup bossGroup = new NioEventLoopGroup();
EventLoopGroup workerGroup = new NioEventLoopGroup();
try {
/**
* 启动服务
*/
ServerBootstrap serverBootstrap = new ServerBootstrap();
serverBootstrap.group(bossGroup, workerGroup)
.channel(NioServerSocketChannel.class)
.handler(new LoggingHandler(LogLevel.INFO))
.option(ChannelOption.SO_BACKLOG, 256)
.option(ChannelOption.SO_KEEPALIVE, true)
.childOption(ChannelOption.TCP_NODELAY, true)
.childHandler(new ChannelInitializer<SocketChannel>() {
@Override
protected void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline pipeline = ch.pipeline();
/**
* 读 超时 触发, WriteIdleTime 和 allIdleTime 为 0 表示不做处理
*/
pipeline.addLast(new IdleStateHandler(30, 0, 0, TimeUnit.SECONDS));
pipeline.addLast(new CommonEncoder(serializer));
pipeline.addLast(new CommonDecoder());
pipeline.addLast(new NettyServerHandler());
}
});
ChannelFuture future = serverBootstrap.bind(port).sync();
future.channel().closeFuture().sync();
} catch (Exception e) {
log.error("Error occurred while starting server! {}",e);
e.printStackTrace();
} finally {
bossGroup.shutdownGracefully();
workerGroup.shutdownGracefully();
}
}
}
Wireshark怎么抓呀,我一直没抓到