I am writing an application to send small file (~2kb) from Netty server to client through WebSocket.
For testing whether the file send success, I had the follows test.
- A client connect to server.
- Setting to drop all packets from server on the client machine.
- The server send a file to the client.
- Checking the result of “ChannelFuture” on the server.
I got true from “future.isSuccess()” and “future.isDone()” immediately when I send a file with ~2kb in this test even client side cannot receive the file.
I repeated this test for files with larger size. I find out that if the file size is larger than ~7kb, the “ChannelFuture future” will wait the feedback from transmission. This is the result I expected.
I am using Netty3.6.1 and my application is built base on “org.jboss.netty.example.http.websocketx.server”.
Here is part of my code:
ChannelBuffer cb = ChannelBuffers.copiedBuffer(myfile_byteArray);
ChannelFuture result = ctx.getChannel().write( new BinaryWebSocketFrame( cb ) );
result.addListener(new ChannelFutureListener() {
public void operationComplete(ChannelFuture future) throws Exception {
if (future.isSuccess()){
System.err.println("future.isSuccess()");
}
if (future.isDone()){
System.err.println("future.isDone()");
}
if (future.isCancelled()){
System.err.println("future.isCancelled()");
}
}
});
Does anyone know how could I having “ChannelFuture” work correctly for file with small file size?
Many thanks in advance!
ChannelFuture will only be notified if the data can be written out to the remote peer. So if it is notified then the other peer received the data without a problem. This is true for all sizes of data.