//Simple enumeration for user commands public enum UserCommand { SEND_MESSAGE, S
ID: 3864163 • Letter: #
Question
//Simple enumeration for user commands
public enum UserCommand {
SEND_MESSAGE, SEND_FILE
}
-----------------------
try {
DataOutputStream output = new DataOutputStream(peerSocket.getOutputStream());
logger.log("Waiting for user text");
while (running) {
String userInput = scanner.nextLine();
UserCommand command = parseUserCommand(userInput);
if (command == UserCommand.SEND_MESSAGE) {
sendTextMessage(output, userInput);
} else {
String filename = parseFilename(userInput);
String filelocation = parseFileLocation(userInput);
sendFile(output, filename, filelocation);
}
output.flush();
}
} catch (IOException e) {
running = false;
}
------------------
could someone explain to me what exactly this class do .
Explanation / Answer
This is a basically chatting Scheme in which the messages are sent to a socket to another user.
in this class there are two things which are happening either user intputs a message to be sent or user sends a file with its location. The user typed message is specified in the if condition if user enters a message it is stored in userinput and sent to the output and in the else condition user specifies a file and its loacation and that file with location is sent to the output . So this class basically does sending message or file to a socket .
Hope this helps....
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.