Al escribir 2048bytes en el controlador, el método messageRevieved se debe llamar dos veces para recibir los datos de todos ... ¿Cómo puedo recibir los datos 2048bytes enen netty, solo podemos escribir y recibir datos de menos de 1024bytes: ¿cómo podemos escribir o recibir más?
Código
Servidor:
public class Server{
public static void main(String[] args){
ChannelFactory factory=new NioServerSocketChannelFactory(
Executors.newCachedThreadPool(),
Executors.newCachedThreadPool());
ServerBootstrap bootstrap=new ServerBootstrap(factory);
bootstrap.setPipelineFactory(new CarPipelineFactory());
bootstrap.setOption("child.tcpNoDelay", true);
bootstrap.setOption("child.keepAlive", true);
bootstrap.bind(new InetSocketAddress(8989));
}
}
Handler servidor:
public class ServerHandler extends SimpleChannelHandler{
public void channelConnected(ChannelHandlerContext ctx, ChannelStateEvent e){
byte[] resp=data.getBytes();//data is a String greater than 1024bytes;
ChannelBuffer buffer=ChannelBuffers.buffer(resp.length);
buffer.writerBytes(resp);
e.getChannel().write(buffer);
buffer.clear();
}
}
Cliente:
public class Client{
public static void main(String[] args){
ChannelFactory channelFactory=new NioClientSocketChannelFactory(
Executors.newCachedThreadPool(),
Executors.newCachedThreadPool());
ClientBootstrap bootstrap=new ClientBootstrap(channelFactory);
bootstrap.getPipeline().addLast("handler", new PhoneClientHandler());
bootstrap.setOption("child.tcpNoDelay", true);
bootstrap.setOption("child.keepAlive", true);
bootstrap.connect(new InetSocketAddress("127.0.0.1",8181));
}
}
Handler Cliente:
public class ClientHandler extends SimpleChannelHandler{
public void messageRecieved(ChannelHandlerContext ctx, ChannelStateEvent e){
ChannelBuffer buffer=(ChannelBuffer)e.getMessage();
int size=buffer.readableBytes();
byte[] bytes=new byte[size];
buffer.readBytes(bytes);
buffer.clear();
System.out.println(new String(bytes));//if the data size>1024,the String will speprate into parts.
}
}
lo siento, no entiendo la pregunta. ¿Puedes tratar de ser más específico? –
lo siento, soy chino y mi inglés no es bueno. a continuación está mi pregunta: como estoy usando netty, cuando escribo 2048bytes (más de 1024bytes) datos de una mano a otra, la mano receptora debería recibir dos veces, cómo puedo revivir toda la información (más de 1024bytes) por una vez ? – Gofier