The reason I need to unblock the application is so I can print the 
throughput to the console after all data has been sent and acknowledged. 
 if I have multiple data channels and the program is blocked only the first 
data channel handler throughput will be printed. So the FileSender.java 
would look as below. But even if I have one data Channel and I attempt to 
close the channel in FileSenderHandler, the main app (FileSender.java) 
still block and hangs on ChannelFuture.channel().closeFuture().sync(); To 
quit, I must type control C at the terminal. 
*ANY IDEAS ON HOW I CAN UNBLOCK THE MAIN APP ONCE ALL DATA IS SENT AND 
RECEIVED?*

*FileSender.java -* *Bootstraps the channel and connects this client/host 
to another host*

public static void main(String[] args) throws Exception {
 // Configure the client/ File Sender
 EventLoopGroup group = new NioEventLoopGroup();
 try {

for (int i =0; i<numOfDataChannels; i++) {

 Bootstrap b = new Bootstrap();
 b.group(group)
 .channel(NioSocketChannel.class)
 .option(ChannelOption.TCP_NODELAY, true)
 .handler(new FileSenderInitializer());

 // Start the client.
 ChannelFuture f = b.connect(HOST, PORT).sync();
 
addChannelFutureToList(f);
}

 // Wait until the connection is closed for each data channel, but also who 
can actually close the channel
for ( ChannelFuture f: channelFutureList){
  f.channel().closeFuture().sync();
}

//When Channel is closed PRINT THROUGHPUT OF ALL THE DATA CHANNELS
printThroughput();
 } finally {
 // Shut down the event loop to terminate all threads.
 group.shutdownGracefully();
 }
 }
}


*FileSenderHandler.java -* *Handles I/O Channel events such as Read/Write*

public void channelRead0(ChannelHandlerContext ctx, ByteBuf msg) throws 
Exception {

try {

 .

 .

 *//After received msg Ack, close the channel, this should unblock the main 
**application (FileSender.java) since after closing the channel closeFuture 
will be fulfilled*

 ctx.channel().close();


}catch(Exception e){

    System.err.printf("ChannelRead Error Msg: " + e.getMessage());
    e.printStackTrace();

}



On Tuesday, January 31, 2017 at 10:03:46 PM UTC-5, L_DisplayName wrote:
>
> Greetings All, 
> I have a FileSender Application that sends data to a server via a 
> FileHandler (not shown here, but in previous post). All data is 
> successfully sent and received, but to keep the FileSenderHandler from 
> terminating early, I had to use the following statement: 
> f.channel().closeFuture().sync(); in the FileSender.java Application (the 
> main application) which blocks the main program preventing it from 
> terminating as well as the FileSenderHandler Application. *My Question 
> is:* HOW CAN I CLOSE THE CHANNEL AND UNBLOCK THE MAIN FileSender 
> APPLICATION ONCE THE FileSenderHandler HAS SUCCESSFULLY SENT AND 
> ACKNOWLEDGED ALL DATA? I currently can't do it within the FileSender 
> class because the application is blocked at that point. I tried closing the 
> channel within the FileSenderHandler class by doing ctx.channel().close() 
> which I thought would unblock the FileSender App since the App is waiting 
> on the close channel event but that didn't work, I also tried closing the 
> channel on the receiver/server side by doing ctx.channel().close() within 
> the FileReceiverHandler but that still didn't unblock the FileSender App. 
> Any help or suggestions would be greatly appreciated.
>
> a*FileSender.java -* *Bootstraps the channel and connects this client/host to 
> another host*
>
> public static void main(String[] args) throws Exception {
>  // Configure the client/ File Sender
>  EventLoopGroup group = new NioEventLoopGroup();
>  try {
>
>  Bootstrp b = new Bootstrap();
>  b.group(group)
>  .channel(NioSocketChannel.class)
>  .option(ChannelOption.TCP_NODELAY, true)
>  .handler(new FileSenderInitializer());
>
>  // Start the client.
>  ChannelFuture f = b.connect(HOST, PORT).sync();
>
>  // Wait until the connection is closed.
>  f.channel().closeFuture().sync();
>  } finally {
>  // Shut down the event loop to terminate all threads.
>  group.shutdownGracefully();
>  }
>  }
> }
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Netty discussions" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/netty/adcdea96-42a2-459a-989f-31950ecce2f7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to