StreamReader(connectionSocket.getInputStream())); DataOutputStream outToClient = new DataOutputStream(connectionSocket.getOutputStream()); String option; while (true) { System.out.println("waiting..."); option = inFromClient.readLine(); switch (option) { case "0": System.out.println("The option is " + option); String username = inFromClient.readLine(); System.out.println("The username is " + username); String password = inFromClient.readLine(); System.out.println("The password is " + password); outToClient.writeBytes("Access Granted\n"); break; case "1": System.out.println("The option is " + option); outToClient.writeBytes("Alice Bob\n"); System.out.println("Alice Bob"); break; case "2": System.out.println("The option is " + option); String receiver = inFromClient.readLine(); System.out.println("The receiver is " + receiver); String message = inFromClient.readLine(); System.out.println("The message is " + message); break; case "3": System.out.println("The option is " + option); outToClient.writeBytes("No message\n"); break; case "4": connectionSocket.close(); break; } if (option.equals("4")) { break; } } } } }
StreamReader(connectionSocket.getInputStream())); DataOutputStream outToClient = new DataOutputStream(connectionSocket.getOutputStream()); String option; while (true) { System.out.println("waiting..."); option = inFromClient.readLine(); switch (option) { case "0": System.out.println("The option is " + option); String username = inFromClient.readLine(); System.out.println("The username is " + username); String password = inFromClient.readLine(); System.out.println("The password is " + password); outToClient.writeBytes("Access Granted\n"); break; case "1": System.out.println("The option is " + option); outToClient.writeBytes("Alice Bob\n"); System.out.println("Alice Bob"); break; case "2": System.out.println("The option is " + option); String receiver = inFromClient.readLine(); System.out.println("The receiver is " + receiver); String message = inFromClient.readLine(); System.out.println("The message is " + message); break; case "3": System.out.println("The option is " + option); outToClient.writeBytes("No message\n"); break; case "4": connectionSocket.close(); break; } if (option.equals("4")) { break; } } } } }
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
Related questions
Question
Can someone please explain to me ASAP??
import java.io.*;
import java.net.*;
class SimpleTextClient {
public static void main(String argv[]) throws Exception
{
BufferedReader inFromUser = new BufferedReader(new InputStreamReader(System.in));
Socket clientSocket = new Socket("127.0.0.1", 8000);
DataOutputStream outToServer = new DataOutputStream(clientSocket.getOutputStream());
BufferedReader inFromServer = new BufferedReader(new InputStreamReader( clientSocket.getInputStream()));
while (true) {
System.out.println("\nYou are connected to the Server.");
System.out.println("\n0. Log in to the server\n1. Get the user list\n2. Send a message\n3. Get my messages\n4. Exit");
System.out.print("\nEnter your option: ");
String option = inFromUser.readLine();
outToServer.writeBytes(option + "\n");
switch (option) {
case "0":
System.out.print("Enter your username: ");
String username = inFromUser.readLine();
System.out.print("Enter your password: ");
String password = inFromUser.readLine();
outToServer.writeBytes(username + "\n");
outToServer.writeBytes(password + "\n");
String response = inFromServer.readLine();
System.out.println(response);
break;
case "1":
System.out.println("User List:");
String user = inFromServer.readLine();
System.out.println(user);
break;
case "2":
System.out.print("Enter the receiver's username: ");
String receiver = inFromUser.readLine();
System.out.print("Enter your message: ");
String message = inFromUser.readLine();
outToServer.writeBytes(receiver + "\n");
outToServer.writeBytes(message + "\n");
break;
case "3":
System.out.println("Your messages:");
String answer = inFromServer.readLine();
System.out.println(answer);
break;
case "4":
clientSocket.close();
}
if (option.equals("4")) {
break;
}
}
}
}
import java.io.*;
import java.net.*;
class SimpleTextServer {
public static void main(String argv[]) throws Exception
{
ServerSocket welcomeSocket = new ServerSocket(8000);
System.out.println("SERVER is running ... ");
while(true) {
Socket connectionSocket = welcomeSocket.accept();
BufferedReader inFromClient = new BufferedReader(new InputStreamReader(connectionSocket.getInputStream()));
DataOutputStream outToClient = new DataOutputStream(connectionSocket.getOutputStream());
String option;
while (true) {
System.out.println("waiting...");
option = inFromClient.readLine();
switch (option) {
case "0":
System.out.println("The option is " + option);
String username = inFromClient.readLine();
System.out.println("The username is " + username);
String password = inFromClient.readLine();
System.out.println("The password is " + password);
outToClient.writeBytes("Access Granted\n");
break;
case "1":
System.out.println("The option is " + option);
outToClient.writeBytes("Alice Bob\n");
System.out.println("Alice Bob");
break;
case "2":
System.out.println("The option is " + option);
String receiver = inFromClient.readLine();
System.out.println("The receiver is " + receiver);
String message = inFromClient.readLine();
System.out.println("The message is " + message);
break;
case "3":
System.out.println("The option is " + option);
outToClient.writeBytes("No message\n");
break;
case "4":
connectionSocket.close();
break;
}
if (option.equals("4")) {
break;
}
}
}
}
}
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 3 steps
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education