SlideShare a Scribd company logo
1 of 4
Download to read offline
please code in java, here is a portion of the code if possible please include all functions of the
program:
import java.io.*;
import java.net.*;
import java.util.*;
public class Chat {
private static final int PORT = 4322;
private static ArrayList<Connection> connections = new ArrayList<>();
public static void main(String[] args) throws IOException {
ServerSocket server = new ServerSocket(PORT);
System.out.println("Server running on port " + PORT);
System.out.println("Type 'help' for a list of available commands");
while (true) {
Socket client = server.accept();
Connection connection = new Connection(client);
connections.add(connection);
connection.start();
}
}
private static class Connection extends Thread {
Socket socket;
BufferedReader in;
PrintWriter out;
String name;
public Connection(Socket socket) {
this.socket = socket;
}
public void run() {
try {
in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
out = new PrintWriter(new OutputStreamWriter(socket.getOutputStream()));
while (true) {
out.println("Enter your name:");
out.flush();
name = in.readLine();
if (name == null) {
return;
}
synchronized (connections) {
for (Connection connection : connections) {
if (connection != this) {
connection.out.println("*** A new user " + name + " entered the chat room !!! ***");
}
}
}
out.println("Welcome " + name + " to our chat room!");
break;
}
while (true) {
String message = in.readLine();
if (message == null) {
return;
}
synchronized (connections) {
for (Connection connection : connections) {
if (connection != this) {
connection.out.println("[" + name + "]: " + message);
}
}
}
}
} catch (IOException e) {
System.out.println(e);
} finally {
try {
socket.close();
} catch (IOException e) {
System.out.println(e);
}
}
}
}
}
1. Objective Getting Started: Familiarize yourself with socket programming. Implement:
Develop a simple chat application for message exchange among remote peers. 2. Getting Started
Socket Programming: Beej Socket Guide: http://beej.us/guide/bgnet 3. Implement 3.1
Programming environment You will write code with any programming language you feel
comfortable. NOTE: You should (1) use TCP Sockets in your peer connection implementation;
(2) handle multiple socket connections; (3) integrate both client-side and server-side code into
one program and run on each peer. 3.2 Running your program Your process (your program when
it is running in memory) will take one command line parameters. The parameter indicates the
port on which your process will listen for the incoming connections. For example, if your
program is called chat, then you can run it like this: ./chat 4322 , where 4322 is the listening port.
Run your program on three computers and perform message exchange. 3.3 Functionality of your
program When launched, your process should work like a UNIX shell. It should accept incoming
connections and at the same time provide a user interface that will offer the following command
options: (Note that specific examples are used for clarity.) 1. help Display information about the
available user interface options or command manual. 2. myip Display the IP address of this
process. Note: The IP should not be your "Local" address (127.0.0.1). It should be the actual IP
of the computer. 3. myport Display the port on which this process is listening for incoming
connections. 4. connect &destination =< port no: : This command establishes a new TCP
connection to the specified edestination > at the specified < port no > . The edestination > is the
IP address of the computer. Any attempt to connect to an invalid P should be rejected and
suitable error message should be displayed. Success or failure in connections between two peers
should be indicated by both the peers using suitable messages. Self-connections and duplicate
connections should be flagged with suitable error messages. 5. list Display a numbered list of all
the connections this process is part of This numbered list will include connections initiated by
this process and connections initiated by other processes. The output should display the I address
and the listening port of all the peers the process is connected to. F 6. terminate < connection id >
This command will terminate the connection listed under the specified number when LIST is
used to display all connections. E.g., terminate 2. In this example, the conmection with
192.168.21.21 should end. An error message is displayed if a valid connection does not exist as
number 2 . If a remote machine terminates one of your comnections, you should also display a
message. 7. send < connection id. >< message > (For example, send 3 Oh! This project is a piece
of cake). This will send the message to the host on the connection that is designated by the
number 3 when command "list" is used. The message to be sent can be up-to 100 characters
long, including blank spaces. On successfully executing the command, the sender should display
"Message sent to connection id " on the screen. On receiving any message from the peer, the
receiver should display the received message along with the sender information. (Eg. If a process
on 192.168.21.20 sends a message to a process on 192.168.21.21 then the output on
192.168.21.21 when receiving a message should display as shown: Message received from
192.168 .21 .20 Sender's Port: Message: " " 8. exit Close all connections and terminate this
process. The other peers should also update their connection list by removing the peer that exits.
please code in java- here is a portion of the code if possible please.pdf

More Related Content

Similar to please code in java- here is a portion of the code if possible please.pdf

Components of computer systems often have dependencies--other co.pdf
Components of computer systems often have dependencies--other co.pdfComponents of computer systems often have dependencies--other co.pdf
Components of computer systems often have dependencies--other co.pdfalamodeindia1
 
TCP Sockets Tutor maXbox starter26
TCP Sockets Tutor maXbox starter26TCP Sockets Tutor maXbox starter26
TCP Sockets Tutor maXbox starter26Max Kleiner
 
Network programming in Java
Network programming in JavaNetwork programming in Java
Network programming in JavaTushar B Kute
 
Socket Programming it-slideshares.blogspot.com
Socket  Programming it-slideshares.blogspot.comSocket  Programming it-slideshares.blogspot.com
Socket Programming it-slideshares.blogspot.comphanleson
 
Socket Programming - nitish nagar
Socket Programming - nitish nagarSocket Programming - nitish nagar
Socket Programming - nitish nagarNitish Nagar
 
Network Programming in Java
Network Programming in JavaNetwork Programming in Java
Network Programming in JavaTushar B Kute
 
Application Layer and Socket Programming
Application Layer and Socket ProgrammingApplication Layer and Socket Programming
Application Layer and Socket Programmingelliando dias
 
Network programming in java - PPT
Network programming in java - PPTNetwork programming in java - PPT
Network programming in java - PPTkamal kotecha
 
Socket programming
Socket programmingSocket programming
Socket programmingAnurag Tomar
 
Lab manual cn-2012-13
Lab manual cn-2012-13Lab manual cn-2012-13
Lab manual cn-2012-13Sasi Kala
 
Network programming in Java
Network programming in JavaNetwork programming in Java
Network programming in JavaTushar B Kute
 
Project Assignment 2 Building a Multi-Threaded Web ServerThis pro.docx
Project Assignment 2 Building a Multi-Threaded Web ServerThis pro.docxProject Assignment 2 Building a Multi-Threaded Web ServerThis pro.docx
Project Assignment 2 Building a Multi-Threaded Web ServerThis pro.docxkacie8xcheco
 
Chatting dengan beberapa pc laptop
Chatting dengan beberapa pc laptopChatting dengan beberapa pc laptop
Chatting dengan beberapa pc laptopyayaria
 

Similar to please code in java- here is a portion of the code if possible please.pdf (20)

Md13 networking
Md13 networkingMd13 networking
Md13 networking
 
Sockets
SocketsSockets
Sockets
 
Components of computer systems often have dependencies--other co.pdf
Components of computer systems often have dependencies--other co.pdfComponents of computer systems often have dependencies--other co.pdf
Components of computer systems often have dependencies--other co.pdf
 
Socket System Calls
Socket System CallsSocket System Calls
Socket System Calls
 
Sockets
Sockets Sockets
Sockets
 
#1 (TCPvs. UDP)
#1 (TCPvs. UDP)#1 (TCPvs. UDP)
#1 (TCPvs. UDP)
 
TCP Sockets Tutor maXbox starter26
TCP Sockets Tutor maXbox starter26TCP Sockets Tutor maXbox starter26
TCP Sockets Tutor maXbox starter26
 
Network programming in Java
Network programming in JavaNetwork programming in Java
Network programming in Java
 
Socket Programming it-slideshares.blogspot.com
Socket  Programming it-slideshares.blogspot.comSocket  Programming it-slideshares.blogspot.com
Socket Programming it-slideshares.blogspot.com
 
Socket Programming - nitish nagar
Socket Programming - nitish nagarSocket Programming - nitish nagar
Socket Programming - nitish nagar
 
Network Programming in Java
Network Programming in JavaNetwork Programming in Java
Network Programming in Java
 
Networking in Java
Networking in JavaNetworking in Java
Networking in Java
 
Application Layer and Socket Programming
Application Layer and Socket ProgrammingApplication Layer and Socket Programming
Application Layer and Socket Programming
 
Network programming in java - PPT
Network programming in java - PPTNetwork programming in java - PPT
Network programming in java - PPT
 
Tcp/ip server sockets
Tcp/ip server socketsTcp/ip server sockets
Tcp/ip server sockets
 
Socket programming
Socket programmingSocket programming
Socket programming
 
Lab manual cn-2012-13
Lab manual cn-2012-13Lab manual cn-2012-13
Lab manual cn-2012-13
 
Network programming in Java
Network programming in JavaNetwork programming in Java
Network programming in Java
 
Project Assignment 2 Building a Multi-Threaded Web ServerThis pro.docx
Project Assignment 2 Building a Multi-Threaded Web ServerThis pro.docxProject Assignment 2 Building a Multi-Threaded Web ServerThis pro.docx
Project Assignment 2 Building a Multi-Threaded Web ServerThis pro.docx
 
Chatting dengan beberapa pc laptop
Chatting dengan beberapa pc laptopChatting dengan beberapa pc laptop
Chatting dengan beberapa pc laptop
 

More from a1salesagency

Please explain in detail and show all steps! a) Assuming all responses.pdf
Please explain in detail and show all steps! a) Assuming all responses.pdfPlease explain in detail and show all steps! a) Assuming all responses.pdf
Please explain in detail and show all steps! a) Assuming all responses.pdfa1salesagency
 
Please explain in steps how to Add an index-html file and how to Uploa.pdf
Please explain in steps how to Add an index-html file and how to Uploa.pdfPlease explain in steps how to Add an index-html file and how to Uploa.pdf
Please explain in steps how to Add an index-html file and how to Uploa.pdfa1salesagency
 
Please Explain Cost of Materials Issuances Under the FIFO Method An in.pdf
Please Explain Cost of Materials Issuances Under the FIFO Method An in.pdfPlease Explain Cost of Materials Issuances Under the FIFO Method An in.pdf
Please Explain Cost of Materials Issuances Under the FIFO Method An in.pdfa1salesagency
 
Please explain answer 8- Write the simplified expression for the Boole.pdf
Please explain answer 8- Write the simplified expression for the Boole.pdfPlease explain answer 8- Write the simplified expression for the Boole.pdf
Please explain answer 8- Write the simplified expression for the Boole.pdfa1salesagency
 
Please examine the figure- -IV- represents- A ribosome A nuclear pore.pdf
Please examine the figure- -IV- represents- A ribosome A nuclear pore.pdfPlease examine the figure- -IV- represents- A ribosome A nuclear pore.pdf
Please examine the figure- -IV- represents- A ribosome A nuclear pore.pdfa1salesagency
 
Please DRAW out how to solve this problem In Drosophila- the genes j a.pdf
Please DRAW out how to solve this problem In Drosophila- the genes j a.pdfPlease DRAW out how to solve this problem In Drosophila- the genes j a.pdf
Please DRAW out how to solve this problem In Drosophila- the genes j a.pdfa1salesagency
 
Please do this in writing form We are learning about the life cycle of.pdf
Please do this in writing form We are learning about the life cycle of.pdfPlease do this in writing form We are learning about the life cycle of.pdf
Please do this in writing form We are learning about the life cycle of.pdfa1salesagency
 
Please create an ERD based on the following configuration in MYSQL- Th.pdf
Please create an ERD based on the following configuration in MYSQL- Th.pdfPlease create an ERD based on the following configuration in MYSQL- Th.pdf
Please create an ERD based on the following configuration in MYSQL- Th.pdfa1salesagency
 
Please code this method for me in Java- StringList is an interface bo.pdf
Please code this method for me in Java-  StringList is an interface bo.pdfPlease code this method for me in Java-  StringList is an interface bo.pdf
Please code this method for me in Java- StringList is an interface bo.pdfa1salesagency
 
Please create a Gantt chart visualisation of the project schedule- Act.pdf
Please create a Gantt chart visualisation of the project schedule- Act.pdfPlease create a Gantt chart visualisation of the project schedule- Act.pdf
Please create a Gantt chart visualisation of the project schedule- Act.pdfa1salesagency
 
Please choose the riiiight answer 11-Cyclical unemployment is caused b.pdf
Please choose the riiiight answer 11-Cyclical unemployment is caused b.pdfPlease choose the riiiight answer 11-Cyclical unemployment is caused b.pdf
Please choose the riiiight answer 11-Cyclical unemployment is caused b.pdfa1salesagency
 
Please can I get the answers ASAP Which of the following for loops wil.pdf
Please can I get the answers ASAP Which of the following for loops wil.pdfPlease can I get the answers ASAP Which of the following for loops wil.pdf
Please can I get the answers ASAP Which of the following for loops wil.pdfa1salesagency
 
Please calculate the labor force participation rate given the followi.pdf
Please calculate the  labor force participation rate given the followi.pdfPlease calculate the  labor force participation rate given the followi.pdf
Please calculate the labor force participation rate given the followi.pdfa1salesagency
 
PLEASE ANSWER URGENTLY! 15- Which of the following term is true about.pdf
PLEASE ANSWER URGENTLY!  15- Which of the following term is true about.pdfPLEASE ANSWER URGENTLY!  15- Which of the following term is true about.pdf
PLEASE ANSWER URGENTLY! 15- Which of the following term is true about.pdfa1salesagency
 
Please answer these following questions Competency7- Informatics and.pdf
Please answer these following questions Competency7-  Informatics and.pdfPlease answer these following questions Competency7-  Informatics and.pdf
Please answer these following questions Competency7- Informatics and.pdfa1salesagency
 
Please answer- Grade 12 Biology Please answer- Grade 12 Biology The e.pdf
Please answer- Grade 12 Biology Please answer- Grade 12 Biology  The e.pdfPlease answer- Grade 12 Biology Please answer- Grade 12 Biology  The e.pdf
Please answer- Grade 12 Biology Please answer- Grade 12 Biology The e.pdfa1salesagency
 
Please answer the three questions- Ty 1- When humans cause a change in.pdf
Please answer the three questions- Ty 1- When humans cause a change in.pdfPlease answer the three questions- Ty 1- When humans cause a change in.pdf
Please answer the three questions- Ty 1- When humans cause a change in.pdfa1salesagency
 
Please answer the question asap and i will surely upvote the answer (D (1).pdf
Please answer the question asap and i will surely upvote the answer (D (1).pdfPlease answer the question asap and i will surely upvote the answer (D (1).pdf
Please answer the question asap and i will surely upvote the answer (D (1).pdfa1salesagency
 
please answer the following - Please select all that apply- 1- Some co.pdf
please answer the following - Please select all that apply- 1- Some co.pdfplease answer the following - Please select all that apply- 1- Some co.pdf
please answer the following - Please select all that apply- 1- Some co.pdfa1salesagency
 
Please answer the question A public bus driver has to go through five.pdf
Please answer the question  A public bus driver has to go through five.pdfPlease answer the question  A public bus driver has to go through five.pdf
Please answer the question A public bus driver has to go through five.pdfa1salesagency
 

More from a1salesagency (20)

Please explain in detail and show all steps! a) Assuming all responses.pdf
Please explain in detail and show all steps! a) Assuming all responses.pdfPlease explain in detail and show all steps! a) Assuming all responses.pdf
Please explain in detail and show all steps! a) Assuming all responses.pdf
 
Please explain in steps how to Add an index-html file and how to Uploa.pdf
Please explain in steps how to Add an index-html file and how to Uploa.pdfPlease explain in steps how to Add an index-html file and how to Uploa.pdf
Please explain in steps how to Add an index-html file and how to Uploa.pdf
 
Please Explain Cost of Materials Issuances Under the FIFO Method An in.pdf
Please Explain Cost of Materials Issuances Under the FIFO Method An in.pdfPlease Explain Cost of Materials Issuances Under the FIFO Method An in.pdf
Please Explain Cost of Materials Issuances Under the FIFO Method An in.pdf
 
Please explain answer 8- Write the simplified expression for the Boole.pdf
Please explain answer 8- Write the simplified expression for the Boole.pdfPlease explain answer 8- Write the simplified expression for the Boole.pdf
Please explain answer 8- Write the simplified expression for the Boole.pdf
 
Please examine the figure- -IV- represents- A ribosome A nuclear pore.pdf
Please examine the figure- -IV- represents- A ribosome A nuclear pore.pdfPlease examine the figure- -IV- represents- A ribosome A nuclear pore.pdf
Please examine the figure- -IV- represents- A ribosome A nuclear pore.pdf
 
Please DRAW out how to solve this problem In Drosophila- the genes j a.pdf
Please DRAW out how to solve this problem In Drosophila- the genes j a.pdfPlease DRAW out how to solve this problem In Drosophila- the genes j a.pdf
Please DRAW out how to solve this problem In Drosophila- the genes j a.pdf
 
Please do this in writing form We are learning about the life cycle of.pdf
Please do this in writing form We are learning about the life cycle of.pdfPlease do this in writing form We are learning about the life cycle of.pdf
Please do this in writing form We are learning about the life cycle of.pdf
 
Please create an ERD based on the following configuration in MYSQL- Th.pdf
Please create an ERD based on the following configuration in MYSQL- Th.pdfPlease create an ERD based on the following configuration in MYSQL- Th.pdf
Please create an ERD based on the following configuration in MYSQL- Th.pdf
 
Please code this method for me in Java- StringList is an interface bo.pdf
Please code this method for me in Java-  StringList is an interface bo.pdfPlease code this method for me in Java-  StringList is an interface bo.pdf
Please code this method for me in Java- StringList is an interface bo.pdf
 
Please create a Gantt chart visualisation of the project schedule- Act.pdf
Please create a Gantt chart visualisation of the project schedule- Act.pdfPlease create a Gantt chart visualisation of the project schedule- Act.pdf
Please create a Gantt chart visualisation of the project schedule- Act.pdf
 
Please choose the riiiight answer 11-Cyclical unemployment is caused b.pdf
Please choose the riiiight answer 11-Cyclical unemployment is caused b.pdfPlease choose the riiiight answer 11-Cyclical unemployment is caused b.pdf
Please choose the riiiight answer 11-Cyclical unemployment is caused b.pdf
 
Please can I get the answers ASAP Which of the following for loops wil.pdf
Please can I get the answers ASAP Which of the following for loops wil.pdfPlease can I get the answers ASAP Which of the following for loops wil.pdf
Please can I get the answers ASAP Which of the following for loops wil.pdf
 
Please calculate the labor force participation rate given the followi.pdf
Please calculate the  labor force participation rate given the followi.pdfPlease calculate the  labor force participation rate given the followi.pdf
Please calculate the labor force participation rate given the followi.pdf
 
PLEASE ANSWER URGENTLY! 15- Which of the following term is true about.pdf
PLEASE ANSWER URGENTLY!  15- Which of the following term is true about.pdfPLEASE ANSWER URGENTLY!  15- Which of the following term is true about.pdf
PLEASE ANSWER URGENTLY! 15- Which of the following term is true about.pdf
 
Please answer these following questions Competency7- Informatics and.pdf
Please answer these following questions Competency7-  Informatics and.pdfPlease answer these following questions Competency7-  Informatics and.pdf
Please answer these following questions Competency7- Informatics and.pdf
 
Please answer- Grade 12 Biology Please answer- Grade 12 Biology The e.pdf
Please answer- Grade 12 Biology Please answer- Grade 12 Biology  The e.pdfPlease answer- Grade 12 Biology Please answer- Grade 12 Biology  The e.pdf
Please answer- Grade 12 Biology Please answer- Grade 12 Biology The e.pdf
 
Please answer the three questions- Ty 1- When humans cause a change in.pdf
Please answer the three questions- Ty 1- When humans cause a change in.pdfPlease answer the three questions- Ty 1- When humans cause a change in.pdf
Please answer the three questions- Ty 1- When humans cause a change in.pdf
 
Please answer the question asap and i will surely upvote the answer (D (1).pdf
Please answer the question asap and i will surely upvote the answer (D (1).pdfPlease answer the question asap and i will surely upvote the answer (D (1).pdf
Please answer the question asap and i will surely upvote the answer (D (1).pdf
 
please answer the following - Please select all that apply- 1- Some co.pdf
please answer the following - Please select all that apply- 1- Some co.pdfplease answer the following - Please select all that apply- 1- Some co.pdf
please answer the following - Please select all that apply- 1- Some co.pdf
 
Please answer the question A public bus driver has to go through five.pdf
Please answer the question  A public bus driver has to go through five.pdfPlease answer the question  A public bus driver has to go through five.pdf
Please answer the question A public bus driver has to go through five.pdf
 

Recently uploaded

Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...anjaliyadav012327
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room servicediscovermytutordmt
 

Recently uploaded (20)

Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 

please code in java- here is a portion of the code if possible please.pdf

  • 1. please code in java, here is a portion of the code if possible please include all functions of the program: import java.io.*; import java.net.*; import java.util.*; public class Chat { private static final int PORT = 4322; private static ArrayList<Connection> connections = new ArrayList<>(); public static void main(String[] args) throws IOException { ServerSocket server = new ServerSocket(PORT); System.out.println("Server running on port " + PORT); System.out.println("Type 'help' for a list of available commands"); while (true) { Socket client = server.accept(); Connection connection = new Connection(client); connections.add(connection); connection.start(); } } private static class Connection extends Thread { Socket socket; BufferedReader in; PrintWriter out; String name; public Connection(Socket socket) { this.socket = socket; } public void run() { try { in = new BufferedReader(new InputStreamReader(socket.getInputStream())); out = new PrintWriter(new OutputStreamWriter(socket.getOutputStream())); while (true) { out.println("Enter your name:"); out.flush(); name = in.readLine();
  • 2. if (name == null) { return; } synchronized (connections) { for (Connection connection : connections) { if (connection != this) { connection.out.println("*** A new user " + name + " entered the chat room !!! ***"); } } } out.println("Welcome " + name + " to our chat room!"); break; } while (true) { String message = in.readLine(); if (message == null) { return; } synchronized (connections) { for (Connection connection : connections) { if (connection != this) { connection.out.println("[" + name + "]: " + message); } } } } } catch (IOException e) { System.out.println(e); } finally { try { socket.close(); } catch (IOException e) { System.out.println(e); } } } } } 1. Objective Getting Started: Familiarize yourself with socket programming. Implement: Develop a simple chat application for message exchange among remote peers. 2. Getting Started
  • 3. Socket Programming: Beej Socket Guide: http://beej.us/guide/bgnet 3. Implement 3.1 Programming environment You will write code with any programming language you feel comfortable. NOTE: You should (1) use TCP Sockets in your peer connection implementation; (2) handle multiple socket connections; (3) integrate both client-side and server-side code into one program and run on each peer. 3.2 Running your program Your process (your program when it is running in memory) will take one command line parameters. The parameter indicates the port on which your process will listen for the incoming connections. For example, if your program is called chat, then you can run it like this: ./chat 4322 , where 4322 is the listening port. Run your program on three computers and perform message exchange. 3.3 Functionality of your program When launched, your process should work like a UNIX shell. It should accept incoming connections and at the same time provide a user interface that will offer the following command options: (Note that specific examples are used for clarity.) 1. help Display information about the available user interface options or command manual. 2. myip Display the IP address of this process. Note: The IP should not be your "Local" address (127.0.0.1). It should be the actual IP of the computer. 3. myport Display the port on which this process is listening for incoming connections. 4. connect &destination =< port no: : This command establishes a new TCP connection to the specified edestination > at the specified < port no > . The edestination > is the IP address of the computer. Any attempt to connect to an invalid P should be rejected and suitable error message should be displayed. Success or failure in connections between two peers should be indicated by both the peers using suitable messages. Self-connections and duplicate connections should be flagged with suitable error messages. 5. list Display a numbered list of all the connections this process is part of This numbered list will include connections initiated by this process and connections initiated by other processes. The output should display the I address and the listening port of all the peers the process is connected to. F 6. terminate < connection id > This command will terminate the connection listed under the specified number when LIST is used to display all connections. E.g., terminate 2. In this example, the conmection with 192.168.21.21 should end. An error message is displayed if a valid connection does not exist as number 2 . If a remote machine terminates one of your comnections, you should also display a message. 7. send < connection id. >< message > (For example, send 3 Oh! This project is a piece of cake). This will send the message to the host on the connection that is designated by the number 3 when command "list" is used. The message to be sent can be up-to 100 characters long, including blank spaces. On successfully executing the command, the sender should display "Message sent to connection id " on the screen. On receiving any message from the peer, the receiver should display the received message along with the sender information. (Eg. If a process on 192.168.21.20 sends a message to a process on 192.168.21.21 then the output on 192.168.21.21 when receiving a message should display as shown: Message received from 192.168 .21 .20 Sender's Port: Message: " " 8. exit Close all connections and terminate this process. The other peers should also update their connection list by removing the peer that exits.