Question: Can you please tell me what this code does? I cannot run it to see so if you could just explain it I would appreciate
Can you please tell me what this code does? I cannot run it to see so if you could just explain it I would appreciate it.
import java.net.*;
import java.io.*;
public class MessageClient
{
public static final int PORT = 6100;
public static final String host = "127.0.0.1";
public static void main(String[] args) throws IOException {
Socket sock = null;
if (args.length != 1) {
System.err.println("Usage: java MessageClient
System.exit(0);
}
try {
/* Comment Here */
sock = new Socket(host, PORT);
PrintWriter pout = new PrintWriter(sock.getOutputStream(),true);
pout.println(args[0]);
/* Comment Here */
ObjectInputStream ois = new ObjectInputStream(sock.getInputStream());
Message message = (Message) ois.readObject();
System.out.println(message.getCharacterCount());
System.out.println(message.getDigitCount());
}
catch (IOException ioe) {
System.err.println(ioe);
}
catch (ClassNotFoundException cnfe) {
System.err.println(cnfe);
}
finally {
sock.close();
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
