parent
4537f00517
commit
333647d1cf
@ -0,0 +1,19 @@
|
||||
package com.baiye;
|
||||
|
||||
import com.baiye.client.NettyClient;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
/**
|
||||
* @author Administrator
|
||||
*/
|
||||
@SpringBootApplication
|
||||
public class NettyClientApplication {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(NettyClientApplication.class, args);
|
||||
|
||||
// FIXME: 2022/7/12 0012 这里直接进行调用进行模拟,整合的话,要把消息接口对外暴露,然后进行发送即可
|
||||
// 建立链接,并发送消息
|
||||
new NettyClient().sendMessage();
|
||||
}
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
package com.baiye.client;
|
||||
|
||||
import com.baiye.dto.TranslatorData;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.ChannelInboundHandlerAdapter;
|
||||
import io.netty.util.ReferenceCountUtil;
|
||||
|
||||
/**
|
||||
* 客户端 消息处理
|
||||
*
|
||||
* @author q
|
||||
* @date 2022/07/12
|
||||
*/
|
||||
public class ClientHandler extends ChannelInboundHandlerAdapter {
|
||||
|
||||
@Override
|
||||
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
|
||||
try{
|
||||
TranslatorData response = (TranslatorData) msg;
|
||||
System.out.println("Client端 :" + response);
|
||||
}finally {
|
||||
// 消息在buffer中,因此要进行释放 -> 方便进行GC
|
||||
// 最后一步如果有写就不需要考虑手动释放, 因为写的底层是用递归写完之后进行释放的
|
||||
ReferenceCountUtil.release(msg);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -1,10 +1,22 @@
|
||||
package com.baiye;
|
||||
|
||||
import com.baiye.server.NettyServer;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
/**
|
||||
* 启动入口
|
||||
*
|
||||
* @author q
|
||||
* @date 2022/07/11
|
||||
*/
|
||||
@SpringBootApplication
|
||||
public class NettyServerApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(NettyServerApplication.class, args);
|
||||
|
||||
// FIXME: 2022/7/12 0012 后续改成SpringBoot的方式进行初始化Server端
|
||||
new NettyServer();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue