I have a server and a client.

The client sends the packet to the server.

In response, it should receive the same packet only with data.

The problem is that I create a new package when it comes back. But after sending the package, I need to get it back (already with the information) and continue working with the information received from the server.

Package:

import io.netty.channel.Channel; public abstract class Packet { public abstract void readPacketData(PacketBuffer buf); public abstract void writePacketData(PacketBuffer buf); public abstract void processPacket(Channel channel, Runnable runnable); public abstract void processPacket(Channel channel); 

}

The incoming packet on the client and server are the same.

  @Override public void channelRead(ChannelHandlerContext ctx, Object msg) { Packet packet = (Packet) msg; packet.processPacket(ctx.channel()); } 

The package that the server receives.

 public abstract class ProxyOnlinePacket extends Packet { private int online; public ProxyOnlinePacket() {} @Override public void writePacketData(PacketBuffer buf) { buf.writeIntLE(ConnectionState.getPacket_ID(this)); buf.writeIntLE(this.online); } @Override public void readPacketData(PacketBuffer buf) { } @Override public void processPacket(Channel channel) { Logger.info("Пришел запрос онлайна!"); online = 200;//Пример. channel.writeAndFlush(this); } 

}

The packet that the client should send to the server.

 public abstract class ProxyOnlinePacket extends Packet { private int online; public ProxyOnlinePacket() {} @Override public void writePacketData(PacketBuffer buf) { buf.writeIntLE(ConnectionState.getPacket_ID(this)); buf.writeIntLE(this.online); } @Override public void readPacketData(PacketBuffer buf) { online = buf.readIntLE(); } @Override public void processPacket(Channel channel) { System.out.print("Пакет пришел обратно!"); } public int getOnline() { return online; } 

}

But here is the problem. I have to get the data in the same place where I sent this packet (to work with the received data)

 ProxyOnlinePacket onlinePacket = new ProxyOnlinePacket(); Proxy.getInstance().sendPacket(onlinePacket);//Отправляю пакет серверу. //Я не понимаю как это сделать. System.out.print("Online: " + onlinePacket.getOnline());//Здесь я уже должен вывести данные которые пришли от сервера. 

As I understand. I need to call the received packet differently. Not like below.

 @Override public void channelRead(ChannelHandlerContext ctx, Object msg) { Packet packet = (Packet) msg; packet.processPacket(ctx.channel()); } 

0