Let’s take a look at a network in the making. This is raw Java code from a brand
ID: 3664477 • Letter: L
Question
Let’s take a look at a network in the making. This is raw Java code from a brand new server. Fill in the blanks in the code so that the server will successfully start running on a localhost. If you have trouble, check the Oracle API. (30 points)
import java.__________.*;
import java.io.*;
public class NewServer
{
//Create a socket for the server to be setup on.
private static __________ server;
//Establish a Port Number for the server.
final static int PORT = 9999;
//Main Execution
public static void main(String[] args)
{
//Catch any exceptions raised in transmission.
try
{
//Create the server’s access point.
server = new __________(__________);
//Print a confirmation message to the console.
System.out.println(“Server started.”);
}
//Catch a possible exception.
catch (__________ ex)
{
//Tell the server what threw the exception.
ex.printStackTrace();
}
}
}
import java.__________.*;
import java.io.*;
public class NewServer
{
//Create a socket for the server to be setup on.
private static __________ server;
//Establish a Port Number for the server.
final static int PORT = 9999;
//Main Execution
public static void main(String[] args)
{
//Catch any exceptions raised in transmission.
try
{
//Create the server’s access point.
server = new __________(__________);
//Print a confirmation message to the console.
System.out.println(“Server started.”);
}
//Catch a possible exception.
catch (__________ ex)
{
//Tell the server what threw the exception.
ex.printStackTrace();
}
}
}
Explanation / Answer
// Please find complete program
import java.net.*;
import java.io.*;
public class NewServer
{
//Create a socket for the server to be setup on.
private static ServerSocket server;
//Establish a Port Number for the server.
final static int PORT = 9999;
//Main Execution
public static void main(String[] args)
{
//Catch any exceptions raised in transmission.
try
{
//Create the server’s access point.
server = new ServerSocket(PORT);
//Print a confirmation message to the console.
System.out.println("Server started.");
}
//Catch a possible exception.
catch (IOException ex)
{
//Tell the server what threw the exception.
ex.printStackTrace();
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.