

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Quiz; Class: Object-Oriented Programming and Design; Subject: COMPUTER SCIENCE; University: University of Arizona; Term: Spring 2007;
Typology: Quizzes
1 / 2
This page cannot be seen from the preview
Don't miss anything!


public class QuizServer { public static void main(String[] args) { try { int port = 4000; ServerSocket socket = null ; socket = new ServerSocket(port); Socket connection = socket.accept(); PrintWriter output = new PrintWriter( new OutputStreamWriter( connection.getOutputStream()), true ); BufferedReader input = new BufferedReader( new InputStreamReader( connection.getInputStream())); String str = input.readLine(); System. out .println("fromClient=" + str); output.println("Good bye"); connection.close(); } catch (Exception e) { } } } public class QuizClient { public static void main(String[] args) { try { String IPAddress = "localhost"; int port = 4000; Socket server = new Socket(IPAddress, port); PrintWriter output = new PrintWriter( new OutputStreamWriter( server.getOutputStream()), true ); BufferedReader input = new BufferedReader( new InputStreamReader( server.getInputStream())); output.println("Hello"); String message = input.readLine(); System. out .println("fromServer = "