Salta ai contenuti. | Salta alla navigazione

Strumenti personali

Daytime Server

Esercizio Java su Networking

Java source code icon daytime.java — Java source code, 701 bytes

Contenuto del file

import java.net.*;
import java.io.*;
public class daytime {
	public static void main(String args[]){
		ServerSocket ss = null;
		try {
			ss = new ServerSocket(13001);
			
			while(true){
				
				try{
					Socket s = ss.accept();
					PrintWriter pw = new PrintWriter( s.getOutputStream(), true );
					pw.println(System.currentTimeMillis());
					s.close();
				}
				catch (IOException e){
					System.err.println("IO S error");
				}
			}
			
			//ss.close(); 
		}
		catch (SecurityException e){
			System.err.println("Security exception");
		}	
		catch (IOException e){
			System.err.println(e);
			System.err.println("IO SS error");
		}
		catch (Exception e){
			System.err.println(e);
		}
	}
}