(TCO 2 and 4) Write the listenSocket method (server-side program) a - Write the
ID: 3907028 • Letter: #
Question
(TCO 2 and 4) Write the listenSocket method (server-side program)
a - Write the required lines of code that will create a ServerSocket object with a port number 2431 on which the server program is going to listen for client communications.
b - Write the required lines of code that will create a new socket object.
c - Write the required lines of code that will read the data sent over the socket connection from the client program.
Copy the above code into the method below:
public void listenSocket(){
// PART A
//PART B
// PART C
}
Explanation / Answer
Answer A:
ServerSocket ss=new ServerSocket(2431);
it will create ServerSocket which listens on the port 2431
Answer B:
Socket sc = ss.accept();
it will establishes the connectiion
answer C:
DataInputStream dis=new DataInputStream(sc.getInputStream());
String str=(String)dis.readUTF();
public void listenSocket(){
ServerSocket ss=new ServerSocket(2431);
Socket sc = ss.accept();
DataInputStream dis=new DataInputStream(sc.getInputStream());
String str=(String)dis.readUTF();
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.