, messageRevieved yöntemi ben, sadece yazmak ve 1024bytes daha az veri alabilir: yazabiliriz veya daha fazla alabilir nasıl? işleyicisi içinde 2048bytes yazarken
Kanununda 2048bytes veri alabilir nasıl ... tüm verileri almak için iki kez çağrılmalıdır
Sunucu:
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));
}
}
Sunucu İşleyici:
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();
}
}
Müşteri:
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));
}
}
Müşteri Handler:
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.
}
}
Üzgünüm soruyu anlamıyorum. Daha spesifik olmaya çalışabilir misin? –
Üzgünüm, bir Çinliyim ve İngilizcem iyi değil. aşağıda benim soru: 2020bytes (herhangi bir 1024bytes daha büyük) veri bir elden diğerine yazdığım zaman, netty kullanarak, alıcı el iki kez, tüm verileri (1024bytes daha büyük) bir kez revieve nasıl ele almak gerekir ? – Gofier