Time Server Example -- Error in documentation

Maverick.Crank.GRey maverick.crank.grey at gmail.com
Fri Sep 9 07:15:16 EDT 2011


Hello Trustin,

Since it will make the example a little bit longer than I expected, I'd like
> to pre-calculate how many milliseconds 70 years from 1900 are and simply add
> it to System.currentTimeMillis().  What do you think?
>
Okay. But I would like to use seconds.
2208988800L seconds = (70 * 365 + 17) * 24 * 60 * 60
70 years
365 days in regular year
17 additional days in leap years
24 hours in day
60 minutes in hour
60 seconds in minute

As a result we have the following code in the method.

@Override
public void channelConnected(ChannelHandlerContext ctx, ChannelStateEvent e)
{
    Channel ch = e.getChannel();

    ChannelBuffer time = ChannelBuffers.buffer(4);
    time.writeInt((int) (System.currentTimeMillis()/1000L + 2208988800L));
    ChannelFuture f = ch.write(time);

    f.addListener(ChannelFutureListener.CLOSE);
}


> Let me also add the instruction on how to test the server using the rdate
> command as you show.
>

It is simple. Since we are running our TimeServer something like
----
// to open ports lower 1024 on Unix-like systems you must be a root
bootstrap.bind(new InetSocketAddress(8037));
----
we can ask rdate use this port (8037) opened on our local interface
(localhost):
----
rdate -o 8037 -p localhost

 -o 8037 - Use port 8037 instead of port 37.
 -p - Do not set, just print the remote time.
 localhost - connect to the local host.
----

I hope it will be enough.
-- 
Be Happy!!!
UIN ICQ: 9487080
skype:maverick.crank.grey


--
View this message in context: http://netty-forums-and-mailing-lists.685743.n2.nabble.com/Time-Server-Example-Error-in-documentation-tp6710743p6775631.html
Sent from the Netty User Group mailing list archive at Nabble.com.


More information about the netty-users mailing list