Reputation: 989
I'm trying to implement a server-application in Netty 4.0 that communicates to the clients via TCP/IP Socket. The client will make an initial connection, once connection is established. The server will send a ping message to the client every X minutes, X can be different for each client. Once the client gets the 'ping' successfully, the client will try to upload/transfer a file to the server. The server receives the file, and writes it to disk.
I'm wondering what would be be the best approach in Netty to do this, mainly the scheduling part (sending the ping message at a cron basis and receiving the file)
I've looked around online, and found there is a Uptime ClientHandler example that connects to server on a timely basis, but that's a client and it's using some method in ClientBootstrap as well (https://github.com/netty/netty/blob/master/example/src/main/java/io/netty/example/uptime/UptimeClientHandler.java#L78)
I've also found a http://netty.io/4.0/api/io/netty/util/HashedWheelTimer.html, but couldn't find any useful examples that elaborates the usage in Netty 4.0.
Any help would be greatly appreciated, thank you very much!!
Upvotes: 4
Views: 5309
Reputation: 23557
Basically you would either use the IdleStateHandler and a ChannelStateHandler implementation which will react on the IdleStateEvent or using directly the eventLoop of the Channel.
For example the eventLoop usage could be like this:
Channel channel = ...
channel.eventLoop().schedule(new PingTask, delay, time unit);
Upvotes: 4