Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // This is the Server code, save as DateServer.java
- import java.net.*;
- import java.io.*;
- import java.util.Date;
- public class DateServer {
- public static void main(String[] args) throws IOException {
- int n=0;
- WorkerThread work;
- try {
- // This creates a listener socket
- ServerSocket sock = new ServerSocket(6013);
- while (true) {
- n++;
- Socket client = sock.accept();
- //WorkerThread work = new WorkerThread(client, n);
- new WorkerThread(client, n).start();
- }
- }
- catch (IOException ioe) {
- System.err.println(ioe);
- }
- }
- }
- class WorkerThread extends Thread{
- private Socket client;
- int numberOfConnections = 0;
- public WorkerThread(Socket client, int numberOfConnections){
- this.client = client;
- this.numberOfConnections = numberOfConnections;
- }
- public void run(){
- try{
- PrintWriter pout = new
- PrintWriter(client.getOutputStream(),true);
- pout.println(new java.util.Date().toString());
- System.out.println("finishing processing client " + numberOfConnections);
- client.close();
- }catch(IOException ioe){}
- }
- }
- //LOOK BELOW
- /* replace DateServer.java with this code.
- javac DateServer.java
- javac DateClient.java
- java DateServer & java DateClient
- java DateServer
- java DateServer
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement