-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDateServer.java
More file actions
31 lines (29 loc) · 1.04 KB
/
DateServer.java
File metadata and controls
31 lines (29 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import java.net.*;
import java.io.*;
public class DateServer extends Thread
{
private ServerSocket sock;
public static void main(String[] args) throws Exception{
new DateServer();
}
public void run(){
try {
ServerSocket sock = new ServerSocket(0);
System.out.println("Listening on socket "+sock.getLocalPort());
/* now listen for connections */
System.out.println("Waiting for connection" + sock.getLocalPort());
Socket client = sock.accept();
System.out.println("Accepted a connection from: "+ client.getInetAddress());
PrintWriter pout = new PrintWriter(client.getOutputStream(), true);
/* write the Date to the socket */
pout.println(new java.util.Date().toString());
/* close the socket and resume */
client.close();
/* listening for connections */
}
catch (IOException ioe) {
System.err.println(ioe);
}
SysLib.exit();
}
}