import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.net.ServerSocket; import java.net.Socket; public class Reservtentaserver { public static final int PORT = 2005; public static void main(String[] args) throws IOException { ServerSocket s = new ServerSocket(PORT); System.out.println("Reservtentaservern: Lyssnar..."); Socket socket = s.accept(); System.out.println("Reservtentaservern: Uppkoppling accepterad."); BufferedReader from_client = new BufferedReader(new InputStreamReader(socket.getInputStream())); PrintWriter to_client = new PrintWriter(new BufferedWriter(new OutputStreamWriter(socket.getOutputStream())), true); // true: PrintWriter is line buffered String inline = from_client.readLine(); System.out.println("Reservtentaservern: Tog emot '" + inline + "'"); to_client.println("HELLO, CLIENT! YOU SAID: " + inline); System.out.println("Reservtentaservern: Avslutar."); } // main } // Reservtentaserver