/Kindly Upvote the answer if it helps to solve your query and comment to ask if you have any queries regarding the solution or approach.
//MultiClient.java
import java.io.*;
import java.net.*;
public class MultiClient
{
public static void main(String[] args) throws Exception
{
Socket sock = new Socket("127.0.0.1", 6789);
// reading from keyboard (keyRead object)
BufferedReader keyRead = new BufferedReader(new
InputStreamReader(System.in));
// sending to client (pwrite object)
OutputStream ostream = sock.getOutputStream();
PrintWriter pwrite = new PrintWriter(ostream, true);
// receiving from server ( receiveRead object)
InputStream istream = sock.getInputStream();
BufferedReader receiveRead = new BufferedReader(new
InputStreamReader(istream));
System.out.println("Start the Chat, type and press Enter key");
String receiveMessage, sendMessage;
while(true)
{
sendMessage = keyRead.readLine(); // keyboard reading
pwrite.println(sendMessage); // sending to server
pwrite.flush(); // flush the data
if((receiveMessage = receiveRead.readLine()) != null) //receive
from server
{
System.out.println(receiveMessage); // displaying at DOS
prompt
}
}
}
}
//MultiServer.java
import java.io.*;
import java.net.*;
public class MultiServer
{
public static void main(String[] args) throws Exception
{
ServerSocket sersock = new ServerSocket(6789);
System.out.println("Server Ready !!");
Socket sock = sersock.accept( );
// reading from keyboard (keyRead object)
BufferedReader keyRead = new BufferedReader(new
InputStreamReader(System.in));
// sending to client (pwrite object)
OutputStream ostream = sock.getOutputStream();
PrintWriter pwrite = new PrintWriter(ostream, true);
// receiving from server ( receiveRead object)
InputStream istream = sock.getInputStream();
BufferedReader receiveRead = new BufferedReader(new
InputStreamReader(istream));
String receiveMessage, sendMessage;
while(true)
{
if((receiveMessage = receiveRead.readLine()) != null)
{
System.out.println(receiveMessage);
}
sendMessage = keyRead.readLine();
pwrite.println(sendMessage);
pwrite.flush();
}
}
}
o/p:
C. C:\WINDOWS\system32\cmd.exe-java Server G. C:\WINDOWS\system32\cmd.exe - O X C:\Users\DELL>g: Microsoft Windows [Version 10.0.18363.778] (c) 2019 Microsoft Corporation. All rights reserved. G:\thread>javac Server.java Server.java:9: error: class SimpleFileServer is public, should be declared C:\Users\DELL>g: public class SimpleFileServer { G:\>G: \thread 1 error "G:\thread' is not recognized as an internal or external command, operable program or batch file. G:\thread>javac Server.java G:\>cdG:\thread G:\thread>java Server The filename, directory name, or volume label syntax is incorrect. Waiting... Accepted connection : Socket[addr=/127.0.0.1,port=56412, localport=132671 G:\>cd thread! Exception in thread "main" java.io.FileNotFoundException: G:\thread\hello.t at java.io.FileInputStream.open(Native Method) G:\thread>javac Client.java at java.io.FileInputStream.open(FileInputStream.java:195) at java.io.FileInputStream.<init>(FileInputStream.java:138) G:\thread>java Client at Server.main(Server.java:30) Connecting... Exception in thread "main" java.lang. ArrayIndexOutOfBounds Exception G:\thread>javac Server.java at java.lang.System.arraycopy (Native Method) Server.java:12: error: illegal escape character at java.io.BufferedoutputStream.write(BufferedOutputStream.java:1 public final static String FILE_TO_SEND ="G:\thread\hello.txt"; // you m28) at Client.main(Client.java:43) 1 error G:\thread>javac Client.java G:\thread>javac Server.java G:\thread>java Client G:\thread>java Server Connecting... Waiting... File G:/thread/hello.txt downloaded (104 bytes read) Accepted connection : Socket[addr=/127.0.0.1, port=56437, localport=13267] Sending G:/thread/hello.txt(104 bytes) G: \thread> Done. Waiting... 10:34 AM ^ M D 1 26-Apr-20
PROBLEM: Design and implement a Java program that enables two users to chat. Using GUIs implement...
Design and implement a Java program that enables two users to chat. Using GUIs implement one user as the server and the other as the client. The sever has two text areas: one for entering text and the other (noneditable) for displaying text received from the client. The client has two text areas: one for receiving text from the server and the other for entering text. When the user presses the enter key, the current line is sent to the...
In this project,use java to write a chat program that enables real-time communication between 3 persons. Specifically the program should permit chat sessions between 2 well as 3 persons,. In case of 3 persons, messages generated by one should reach the other two (Its a conferencing facility and not an individual chat facility). The chat program needs to allow a user to type messages, which should be conveyed to the other end(s) and displayed at the other end(s). The user...
implement the follwing code using command promp or Eclipse or
any other program you are familiar with. keep the name of the
classes exatcly the same as requested for testing purpose. please
follow each instruction provided below
Objective of this assignment o get you famililar with developing and implementing TCP or UDP sockets. What you need to do: I. Implement a simple TCP Client-Server application 2. and analyze round trip time measurements for each of the above applications 3. The...
JAVA Problem: Coffee Design and implement a program that manages coffees. First, implement an abstract class named Coffee. The Coffee class has three member variables: coffee type, price, and store name. The Coffee class has an abstract method name ingredient. Make sure to add all necessary setters and getters as well as other methods. The class Coffee implements an interface HowToMakeDrink. The interface has the following method: public interface HowToMakeDrink { public void prepare (); } The prepare method will...
Problem: Coffee(Java) Design and implement a program that manages coffees. First, implement an abstract class named Coffee. The Coffee class has three member variables: coffee type(does not mention the data type of the variable coffeeType), price, and store name. The Coffee class has an abstract method name ingredient. Make sure to add all necessary setters and getters as well as other methods. The class Coffee implements an interface HowToMakeDrink. The interface has the following method: public interface HowToMakeDrink { public...
In this assignment, you design a simple chat room in the form of a network application which uses the services of a TCP/IP computer network. Your design should have a clientserver architecture in which the server is multi-threaded. Then, you need to implement the server-side of the chat-room application in Java (implementing the client-side is optional). The server maintains a list (an ArrayList will work well) of all the active connections. It will listen on a port for a new...
I have to modify a server program and chat program to work as the following instructions but I am completely clueless as to where to start. I'd appreciate any help on how to atleast get started. This must be done in java. Diffie-Hellman Two parties use a key agreement protocol to generate identical secret keys for encryption without ever having to transmit the secret key. The protocol works by both parties agreeing on a set of values (a) and (q)....
JAVA Problem: Coffee do not use ArrayList or Case Design and implement a program that manages coffees. First, implement an abstract class named Coffee. The Coffee class has three member variables: coffee type, price, and store name. The Coffee class has an abstract method name ingredient. Make sure to add all necessary setters and getters as well as other methods. The class Coffee implements an interface HowToMakeDrink. The interface has the following method: public interface HowToMakeDrink { public void prepare ();...
in JAVA program.Use top-down design to design and implement a program to ask the user to enter a list of integers, and then display to the user the mean and median of this list. You should first prompt the user to specify the length of the list of integers. For this assignment, your code should create an array of size 10, and then allow the user to specify the number of integers in their list, up to a maximum of...
Design and implement a Java program (name it PasswordTest) that accepts a string from the user and evaluates it as a password, giving it a valid or invalid verdict A good password will be at least 8 characters and includes at least one lower-case letter, at least one upper-case letter, at least one digit, and at least one character that is neither a letter nor a digit. Your program will need to check each character in the string in order...