0
안드로이드와 서버에 클라이언트 연결이 성공했습니다.안드로이드 클라이언트에서 서버로 Netty (tcp)를 사용하여 서버에
하지만 "안녕하세요"와 같은 메시지를 보내려는 경우 메시지가 사라졌습니다.
이 내 클라이언트 코드 :
group = new OioEventLoopGroup();
Bootstrap b = new Bootstrap();
b.group(group);
b.channel(OioSocketChannel.class);
b.option(ChannelOption.SO_KEEPALIVE, true);
b.handler(new ChannelInitializer<SocketChannel>() {
@Override
public void initChannel(SocketChannel ch) throws Exception {
ch.pipeline().addLast(handler);
}
});
Channel ch = null;
ChannelFuture f = null;
try {
f = b.connect(new InetSocketAddress(host, port)).sync();
ch = f.channel();
} catch (InterruptedException e) {
e.printStackTrace();
}
ch.writeAndFlush("hello!");
이 내 서버 코드입니다 : 내가 연결할 때
@Override
public void channelActive(ChannelHandlerContext ctx){
channels.add(ctx.channel());
ctx.channel().writeAndFlush("Welcome My Server");
System.out.println(ctx.channel().remoteAddress());
}
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) {
ByteBuf in = (ByteBuf) msg;
try {
while (in.isReadable()) {
System.out.print((char) in.readByte());
System.out.flush();
}
} finally {
ReferenceCountUtil.release(msg);
}
}
, 서버가 인쇄 된 '연결된 클라이언트의 IP 주소' 하지만 그 이후 ' 안녕하세요 '메시지가 내 서버에 인쇄되지 않습니다. 무엇이 잘못 되었나요? 섬기는 사람? 고객? 인코딩, 디코딩이 문제가되지 않는다고 생각합니다. 아무것도 수신하지 못했습니다. 그 방법을 알려주십시오.