This server retrieves the time using the RFC867 protocol. : Server « Network Protocol « Java






This server retrieves the time using the RFC867 protocol.

This server retrieves the time using the RFC867 protocol.
  
/*
Chapter 3 - Simple Protocols
Java 2 Network Protocols Black Book
by Al Williams    
Paraglyph Press 2001
*/



import java.net.*;
import java.io.*;

public class Time867 {
    public static void main(String[] args) {
        String hostname = "tock.usno.navy.mil";
        if (args.length==1) hostname=args[0];
        try {
        int c;
        Socket sock=new Socket(hostname,13);
        InputStream is = sock.getInputStream();
        do {
          c=is.read();
          if (c!=-1) System.out.print((char)c);
           } while (c!=-1);
        }
        catch (IOException e) { System.out.println(e); }
    }
}
           
         
    
  








Related examples in the same category

1.A generic framework for a flexible, multi-threaded server
2.Server allows connections on socket 6123Server allows connections on socket 6123
3.This server displays messages to a single clientThis server displays messages to a single client
4.The client can specify information to control the output of a serverThe client can specify information to control the output of a server
5.A server can use specialized streams to deliver typed dataA server can use specialized streams to deliver typed data
6.Serve entire objects using ObjectOutputStreamServe entire objects using ObjectOutputStream
7.A multithreaded serverA multithreaded server
8.Base class to build multithreaded servers easily
9.Manage a pool of threads for clients
10.Client estimates the speed of the network connection to the server
11.Quote Server
12.Logging Server based on SocketServer
13.Client and Server Demo
14.Reflector
15.Simple Http Server