Time Server Example -- Error in documentation

이희승 (Trustin Lee) trustin at gmail.com
Wed Sep 7 23:33:00 EDT 2011


 Hi, 

Thanks for the feed back. 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?

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

Thanks a lot!
-- 
Trustin Lee (http://gleamynode.net/)

On Wednesday, September 7, 2011 at 10:59 PM, Maverick.Crank.GRey wrote:

> Hello Trustin,
> 
> In additional to the issue found by Tiberiu I would like to mentioned that 
> http://docs.jboss.org/netty/3.2/guide/html_single/index.html#d0e440 the
> suggested implementation of http://tools.ietf.org/html/rfc868 TIME
> protocol (RFC 868) is incorrect. According to RFC 868 "The Time service
> sends back to the originating source the time in seconds since midnight on
> *January first 1900*." and not "the difference, measured in milliseconds,
> between the current time and midnight, *January 1, 1970 UTC*" returned by 
> http://download.oracle.com/javase/6/docs/api/java/lang/System.html#currentTimeMillis()
> java.lang.System.currentTimeMillis() .
> 
> Here is a little bit corrected example of TimeServerHandler
> 
> package ru.spb.mcgrey.test.java.netty.server;
> 
> import org.jboss.netty.buffer.ChannelBuffer;
> import org.jboss.netty.buffer.ChannelBuffers;
> import org.jboss.netty.channel.*;
> 
> import java.util.Calendar;
> 
> 
> public class TimeServerHandler extends SimpleChannelHandler {
> 
>  @Override
>  public void channelConnected(ChannelHandlerContext ctx,
> ChannelStateEvent e) {
>  Channel ch = e.getChannel();
> 
>  ChannelBuffer time = ChannelBuffers.buffer(4);
> 
>  Calendar rightNow = Calendar.getInstance();
>  rightNow.roll(Calendar.YEAR, 70); // to be comply with RFC 868
> 
>  long timeMs = rightNow.getTimeInMillis();
>  long timeS = timeMs / 1000;
>  time.writeInt((int)timeS);
> 
>  ChannelFuture f = ch.write(time);
> 
>  f.addListener(ChannelFutureListener.CLOSE);
>  }
> 
>  @Override
>  public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e)
> {
>  e.getCause().printStackTrace();
>  e.getChannel().close();
>  }
> }
> 
> BTW, being comply with RFC 868 gives us the additional advantage. We can use
> standard tools to test our time server instead of writing a Time Client. I
> used http://linux.die.net/man/1/rdate rdate for my tests.
> 
> $ rdate -o 8037 -p localhost
> Thu Sep 8 17:45:27 UTC 2011
> 
> I date to hope, my post can make Netty documentation a little bit correctly
> =) 
> 
> 
> --
> View this message in context: http://netty-forums-and-mailing-lists.685743.n2.nabble.com/Time-Server-Example-Error-in-documentation-tp6710743p6767899.html
> Sent from the Netty User Group mailing list archive at Nabble.com (http://Nabble.com).
> _______________________________________________
> netty-users mailing list
> netty-users at lists.jboss.org (mailto:netty-users at lists.jboss.org)
> https://lists.jboss.org/mailman/listinfo/netty-users

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/netty-users/attachments/20110908/0ec25f7d/attachment.html 


More information about the netty-users mailing list