public class SimpleNTPServer extends Object implements Runnable
Constructor and Description |
---|
SimpleNTPServer()
Create SimpleNTPServer listening on default NTP port.
|
SimpleNTPServer(int port)
Create SimpleNTPServer.
|
Modifier and Type | Method and Description |
---|---|
void |
connect()
Connect to server socket and listen for client connections.
|
int |
getPort() |
protected void |
handlePacket(DatagramPacket request,
long rcvTime)
Handle incoming packet.
|
boolean |
isRunning()
Return state of whether time service is running.
|
boolean |
isStarted()
Return state of whether time service is running.
|
static void |
main(String[] args) |
void |
run()
main thread to service client connections.
|
void |
start()
Start time service and provide time to client connections.
|
void |
stop()
Close server socket and stop listening.
|
public SimpleNTPServer()
public SimpleNTPServer(int port)
port
- the local port the server socket is bound to, or
zero
for a system selected free port.IllegalArgumentException
- if port number less than 0public int getPort()
public boolean isRunning()
public boolean isStarted()
public void connect() throws IOException
IOException
- if an I/O error occurs when creating the socket.public void start() throws IOException
IOException
- if an I/O error occurs when creating the socket.public void run()
protected void handlePacket(DatagramPacket request, long rcvTime) throws IOException
request
- incoming DatagramPacketrcvTime
- time packet receivedIOException
- if an I/O error occurs.public void stop()
public static void main(String[] args)