Solved

Which Code Fragment Creates a Server Running at Port 6666

Question 16

Multiple Choice

Which code fragment creates a server running at port 6666 and sends one line of text, "Hello from earth" over and over to any machine that connects to the server.


A) ServerSocket ss = new ServerSocket(6666) ;
Socket sock = ss.accept() ;
While (true)
{
PrintWriter pw = new PrintWriter(sock.getOutputStream() ) ;
Pw) println("Hello from earth") ;
Pw) flush() ;
Pw) close() ;
}
B) ServerSocket ss = new ServerSocket(6666) ;
While (true)
{
PrintWriter pw = new PrintWriter(sock.getOutputStream() ) ;
Pw) println("Hello from earth") ;
Socket sock = ss.accept() ;
}
C) ServerSocket ss = new ServerSocket(6666) ;
While (true)
{
Socket sock = ss.accept() ;
PrintWriter pw = new PrintWriter(sock.getOutputStream() ) ;
Pw) println("Hello from earth") ;
Pw) flush() ;
Pw) close() ;
}
D) Socket sock = ss.accept() ;
While (true)
{
ServerSocket ss = new ServerSocket(6666) ;
PrintWriter pw = new PrintWriter(sock.getOutputStream() ) ;
Pw) println("Hello from earth") ;
Pw) flush() ;
Pw) close() ;
}

Correct Answer:

verifed

Verified

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

Related Questions