Solved

Suppose That Sock Refers to a TCP Socket Connected to Another

Question 32

Multiple Choice

Suppose that sock refers to a TCP socket connected to another machine, and in is aScanner. Which code sends the string "Who is there?" to the other machine, receives the return answer, and then prints it?


A) PrintWriter pw = new PrintWriter(sock.getOutputStream() .println("Who is there?") ) ;
InputStream instream = sock.getInputStream() ;
Scanner in = new Scanner(instream) ;
System.out.println(in.nextLine() ) ;
B) PrintWriter pw = new PrintWriter(sock.getInputStream() ) ;
pw.println("Who is there?") ;
pw.flush() ;
InputStream instream = sock.getInputStream() ;
Scanner in = new Scanner(instream) ;
System.out.println(in.nextLine() ) ;
C) PrintWriter pw = new PrintWriter(sock.getOutputStream() ) ;
pw.flush("Who is there") ;
InputStream instream = sock.getInputStream() ;
Scanner in = new Scanner(instream) ;
System.out.println(in.nextLine() ) ;
D) PrintWriter pw = new PrintWriter(sock.getOutputStream() ) ;
pw.println("Who is there?") ;
pw.flush() ;
InputStream instream = sock.getInputStream() ;
Scanner in = new Scanner(instream) ;
System.out.println(in.nextLine() ) ;

Correct Answer:

verifed

Verified

Unlock this answer now
Get Access to more Verified Answers free of charge

Related Questions

Unlock this Answer For Free Now!

View this answer and more for free by performing one of the following actions

qr-code

Scan the QR code to install the App and get 2 free unlocks

upload documents

Unlock quizzes for free by uploading documents