SlideShare une entreprise Scribd logo
B.CHAT
AIM:
To implement a CHAT application using TCP Socket.
Concept:
1. It uses TCP socket communication .We have a server as well as a client.
2. Both can be run in the same machine or different machines. If both are running in
the machine, the address to be given at the client side is local host address.
3. If both are running in different machines, then in the client side we need to specify
the ip address of machine in which server application is running.
Program:
Chatserver.java:
import java.net.*;
import java.io.*;
public class chatserver
{
public static void main(String args[]) throws Exception
{
ServerSocket ss=new ServerSocket(2000);
Socket sk=ss.accept();
BufferedReader cin=new BufferedReader(new
InputStreamReader(sk.getInputStream()));
PrintStream cout=new PrintStream(sk.getOutputStream());
BufferedReader stdin=new BufferedReader(new InputStreamReader(System.in));
String s;
while ( true )
{
s=cin.readLine();
if (s.equalsIgnoreCase("END"))
{
cout.println("BYE");
break;
}
System. out.print("Client : "+s+"n");
System.out.print("Server : ");
s=stdin.readLine();
cout.println(s);
}
ss.close();
sk.close();
cin.close();
cout.close();
stdin.close();
}
}
Chatclient.java
import java.net.*;
import java.io.*;
public class chatclient
{
public static void main(String args[]) throws Exception
{
Socket sk=new Socket("127.0.0.1",2000);
BufferedReader sin=new BufferedReader(new
InputStreamReader(sk.getInputStream()));
PrintStream sout=new PrintStream(sk.getOutputStream());
BufferedReader stdin=new BufferedReader(new InputStreamReader(System.in));
String s;
while ( true )
{
System.out.print("Client : ");
s=stdin.readLine();
sout.println(s);
s=sin.readLine();
System.out.print("Server : "+s+"n");
if ( s.equalsIgnoreCase("BYE") )
break;
}
sk.close();
sin.close();
sout.close();
stdin.close();
}
}
OUTPUT:
Server:
E:nwlab>javac *.java
E:nwlab>java chatserver
Client : hi
Server : hi
Client:
E:nwlab>java chatclient
Client : hi
Server : hi
Client :
Result:
CHAT application using TCP Socket is implemented successfully.

Contenu connexe

Similaire à networks-lab-excercise4.pdf

A.java
A.javaA.java
java networking
 java networking java networking
java networking
Waheed Warraich
 
Network Programming in Java
Network Programming in JavaNetwork Programming in Java
Network Programming in Java
Tushar B Kute
 
Os 2
Os 2Os 2
EN-04 (1).pptx
EN-04 (1).pptxEN-04 (1).pptx
EN-04 (1).pptx
TienTran779192
 
Lab manual cn-2012-13
Lab manual cn-2012-13Lab manual cn-2012-13
Lab manual cn-2012-13
Sasi Kala
 
Network programming in Java
Network programming in JavaNetwork programming in Java
Network programming in Java
Tushar B Kute
 
Md13 networking
Md13 networkingMd13 networking
Md13 networking
Rakesh Madugula
 
Linux Systems Prograramming: Unix Domain, Internet Domain (TCP, UDP) Socket P...
Linux Systems Prograramming: Unix Domain, Internet Domain (TCP, UDP) Socket P...Linux Systems Prograramming: Unix Domain, Internet Domain (TCP, UDP) Socket P...
Linux Systems Prograramming: Unix Domain, Internet Domain (TCP, UDP) Socket P...
RashidFaridChishti
 
Advance Java-Network Programming
Advance Java-Network ProgrammingAdvance Java-Network Programming
Advance Java-Network Programming
ashok hirpara
 
Client server chat application
Client server chat applicationClient server chat application
Client server chat application
Samsil Arefin
 
[Type text]ECET465Project 2Project Assignment 2 Building a Mul.docx
[Type text]ECET465Project 2Project Assignment 2 Building a Mul.docx[Type text]ECET465Project 2Project Assignment 2 Building a Mul.docx
[Type text]ECET465Project 2Project Assignment 2 Building a Mul.docx
hanneloremccaffery
 
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
kacie8xcheco
 
Unit 8 Java
Unit 8 JavaUnit 8 Java
Unit 8 Java
arnold 7490
 
Socket programming using java
Socket programming using javaSocket programming using java
Socket programming using java
UC San Diego
 
TCP IP
TCP IPTCP IP
TCP IP
hivasu
 
Sockets
SocketsSockets
Sockets
sivindia
 
Socket programming
Socket programmingSocket programming
Socket programming
Anurag Tomar
 
Networking in Java
Networking in JavaNetworking in Java
Networking in Java
Tushar B Kute
 
Network programming in Java
Network programming in JavaNetwork programming in Java
Network programming in Java
Tushar B Kute
 

Similaire à networks-lab-excercise4.pdf (20)

A.java
A.javaA.java
A.java
 
java networking
 java networking java networking
java networking
 
Network Programming in Java
Network Programming in JavaNetwork Programming in Java
Network Programming in Java
 
Os 2
Os 2Os 2
Os 2
 
EN-04 (1).pptx
EN-04 (1).pptxEN-04 (1).pptx
EN-04 (1).pptx
 
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
 
Md13 networking
Md13 networkingMd13 networking
Md13 networking
 
Linux Systems Prograramming: Unix Domain, Internet Domain (TCP, UDP) Socket P...
Linux Systems Prograramming: Unix Domain, Internet Domain (TCP, UDP) Socket P...Linux Systems Prograramming: Unix Domain, Internet Domain (TCP, UDP) Socket P...
Linux Systems Prograramming: Unix Domain, Internet Domain (TCP, UDP) Socket P...
 
Advance Java-Network Programming
Advance Java-Network ProgrammingAdvance Java-Network Programming
Advance Java-Network Programming
 
Client server chat application
Client server chat applicationClient server chat application
Client server chat application
 
[Type text]ECET465Project 2Project Assignment 2 Building a Mul.docx
[Type text]ECET465Project 2Project Assignment 2 Building a Mul.docx[Type text]ECET465Project 2Project Assignment 2 Building a Mul.docx
[Type text]ECET465Project 2Project Assignment 2 Building a Mul.docx
 
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
 
Unit 8 Java
Unit 8 JavaUnit 8 Java
Unit 8 Java
 
Socket programming using java
Socket programming using javaSocket programming using java
Socket programming using java
 
TCP IP
TCP IPTCP IP
TCP IP
 
Sockets
SocketsSockets
Sockets
 
Socket programming
Socket programmingSocket programming
Socket programming
 
Networking in Java
Networking in JavaNetworking in Java
Networking in Java
 
Network programming in Java
Network programming in JavaNetwork programming in Java
Network programming in Java
 

Plus de Jayaprasanna4

ethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.pptethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.ppt
Jayaprasanna4
 
ethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.pptethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.ppt
Jayaprasanna4
 
Human computer Interaction ch1-the human.pdf
Human computer Interaction ch1-the human.pdfHuman computer Interaction ch1-the human.pdf
Human computer Interaction ch1-the human.pdf
Jayaprasanna4
 
computer Networks Error Detection and Correction.ppt
computer Networks Error Detection and Correction.pptcomputer Networks Error Detection and Correction.ppt
computer Networks Error Detection and Correction.ppt
Jayaprasanna4
 
HUman computer Interaction Socio-organizational Issues.ppt
HUman computer Interaction Socio-organizational Issues.pptHUman computer Interaction Socio-organizational Issues.ppt
HUman computer Interaction Socio-organizational Issues.ppt
Jayaprasanna4
 
human computer Interaction cognitive models.ppt
human computer Interaction cognitive models.ppthuman computer Interaction cognitive models.ppt
human computer Interaction cognitive models.ppt
Jayaprasanna4
 
World wide web and Hyper Text Markup Language
World wide web and Hyper Text Markup LanguageWorld wide web and Hyper Text Markup Language
World wide web and Hyper Text Markup Language
Jayaprasanna4
 
CI-Monte-Carlo.ppt
CI-Monte-Carlo.pptCI-Monte-Carlo.ppt
CI-Monte-Carlo.ppt
Jayaprasanna4
 
Activity planning.ppt
Activity planning.pptActivity planning.ppt
Activity planning.ppt
Jayaprasanna4
 
Cost effort.ppt
Cost effort.pptCost effort.ppt
Cost effort.ppt
Jayaprasanna4
 
Activity planning.ppt
Activity planning.pptActivity planning.ppt
Activity planning.ppt
Jayaprasanna4
 
unit-1.ppt
unit-1.pptunit-1.ppt
unit-1.ppt
Jayaprasanna4
 
BGP.ppt
BGP.pptBGP.ppt
BGP.ppt
Jayaprasanna4
 
Lecture 19- Multicasting.ppt
Lecture 19- Multicasting.pptLecture 19- Multicasting.ppt
Lecture 19- Multicasting.ppt
Jayaprasanna4
 
line coding.ppt
line coding.pptline coding.ppt
line coding.ppt
Jayaprasanna4
 
error detection.ppt
error detection.ppterror detection.ppt
error detection.ppt
Jayaprasanna4
 
connecting LANs.pptx
connecting LANs.pptxconnecting LANs.pptx
connecting LANs.pptx
Jayaprasanna4
 
CS1302 06NOV.pdf
CS1302 06NOV.pdfCS1302 06NOV.pdf
CS1302 06NOV.pdf
Jayaprasanna4
 
session and cookies.ppt
session and cookies.pptsession and cookies.ppt
session and cookies.ppt
Jayaprasanna4
 
JDBC.ppt
JDBC.pptJDBC.ppt
JDBC.ppt
Jayaprasanna4
 

Plus de Jayaprasanna4 (20)

ethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.pptethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.ppt
 
ethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.pptethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.ppt
 
Human computer Interaction ch1-the human.pdf
Human computer Interaction ch1-the human.pdfHuman computer Interaction ch1-the human.pdf
Human computer Interaction ch1-the human.pdf
 
computer Networks Error Detection and Correction.ppt
computer Networks Error Detection and Correction.pptcomputer Networks Error Detection and Correction.ppt
computer Networks Error Detection and Correction.ppt
 
HUman computer Interaction Socio-organizational Issues.ppt
HUman computer Interaction Socio-organizational Issues.pptHUman computer Interaction Socio-organizational Issues.ppt
HUman computer Interaction Socio-organizational Issues.ppt
 
human computer Interaction cognitive models.ppt
human computer Interaction cognitive models.ppthuman computer Interaction cognitive models.ppt
human computer Interaction cognitive models.ppt
 
World wide web and Hyper Text Markup Language
World wide web and Hyper Text Markup LanguageWorld wide web and Hyper Text Markup Language
World wide web and Hyper Text Markup Language
 
CI-Monte-Carlo.ppt
CI-Monte-Carlo.pptCI-Monte-Carlo.ppt
CI-Monte-Carlo.ppt
 
Activity planning.ppt
Activity planning.pptActivity planning.ppt
Activity planning.ppt
 
Cost effort.ppt
Cost effort.pptCost effort.ppt
Cost effort.ppt
 
Activity planning.ppt
Activity planning.pptActivity planning.ppt
Activity planning.ppt
 
unit-1.ppt
unit-1.pptunit-1.ppt
unit-1.ppt
 
BGP.ppt
BGP.pptBGP.ppt
BGP.ppt
 
Lecture 19- Multicasting.ppt
Lecture 19- Multicasting.pptLecture 19- Multicasting.ppt
Lecture 19- Multicasting.ppt
 
line coding.ppt
line coding.pptline coding.ppt
line coding.ppt
 
error detection.ppt
error detection.ppterror detection.ppt
error detection.ppt
 
connecting LANs.pptx
connecting LANs.pptxconnecting LANs.pptx
connecting LANs.pptx
 
CS1302 06NOV.pdf
CS1302 06NOV.pdfCS1302 06NOV.pdf
CS1302 06NOV.pdf
 
session and cookies.ppt
session and cookies.pptsession and cookies.ppt
session and cookies.ppt
 
JDBC.ppt
JDBC.pptJDBC.ppt
JDBC.ppt
 

Dernier

Swimming pool mechanical components design.pptx
Swimming pool  mechanical components design.pptxSwimming pool  mechanical components design.pptx
Swimming pool mechanical components design.pptx
yokeleetan1
 
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECTCHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
jpsjournal1
 
Generative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of contentGenerative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of content
Hitesh Mohapatra
 
spirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptxspirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptx
Madan Karki
 
A SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMS
A SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMSA SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMS
A SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMS
IJNSA Journal
 
14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application
SyedAbiiAzazi1
 
22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt
KrishnaveniKrishnara1
 
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
IJECEIAES
 
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdfBPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
MIGUELANGEL966976
 
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student MemberIEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
VICTOR MAESTRE RAMIREZ
 
Wearable antenna for antenna applications
Wearable antenna for antenna applicationsWearable antenna for antenna applications
Wearable antenna for antenna applications
Madhumitha Jayaram
 
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODELDEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
gerogepatton
 
Properties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptxProperties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptx
MDSABBIROJJAMANPAYEL
 
2. Operations Strategy in a Global Environment.ppt
2. Operations Strategy in a Global Environment.ppt2. Operations Strategy in a Global Environment.ppt
2. Operations Strategy in a Global Environment.ppt
PuktoonEngr
 
basic-wireline-operations-course-mahmoud-f-radwan.pdf
basic-wireline-operations-course-mahmoud-f-radwan.pdfbasic-wireline-operations-course-mahmoud-f-radwan.pdf
basic-wireline-operations-course-mahmoud-f-radwan.pdf
NidhalKahouli2
 
132/33KV substation case study Presentation
132/33KV substation case study Presentation132/33KV substation case study Presentation
132/33KV substation case study Presentation
kandramariana6
 
Embedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoringEmbedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoring
IJECEIAES
 
ML Based Model for NIDS MSc Updated Presentation.v2.pptx
ML Based Model for NIDS MSc Updated Presentation.v2.pptxML Based Model for NIDS MSc Updated Presentation.v2.pptx
ML Based Model for NIDS MSc Updated Presentation.v2.pptx
JamalHussainArman
 
5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...
5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...
5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...
ihlasbinance2003
 
sieving analysis and results interpretation
sieving analysis and results interpretationsieving analysis and results interpretation
sieving analysis and results interpretation
ssuser36d3051
 

Dernier (20)

Swimming pool mechanical components design.pptx
Swimming pool  mechanical components design.pptxSwimming pool  mechanical components design.pptx
Swimming pool mechanical components design.pptx
 
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECTCHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
 
Generative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of contentGenerative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of content
 
spirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptxspirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptx
 
A SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMS
A SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMSA SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMS
A SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMS
 
14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application
 
22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt
 
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
 
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdfBPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
 
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student MemberIEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
 
Wearable antenna for antenna applications
Wearable antenna for antenna applicationsWearable antenna for antenna applications
Wearable antenna for antenna applications
 
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODELDEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
DEEP LEARNING FOR SMART GRID INTRUSION DETECTION: A HYBRID CNN-LSTM-BASED MODEL
 
Properties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptxProperties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptx
 
2. Operations Strategy in a Global Environment.ppt
2. Operations Strategy in a Global Environment.ppt2. Operations Strategy in a Global Environment.ppt
2. Operations Strategy in a Global Environment.ppt
 
basic-wireline-operations-course-mahmoud-f-radwan.pdf
basic-wireline-operations-course-mahmoud-f-radwan.pdfbasic-wireline-operations-course-mahmoud-f-radwan.pdf
basic-wireline-operations-course-mahmoud-f-radwan.pdf
 
132/33KV substation case study Presentation
132/33KV substation case study Presentation132/33KV substation case study Presentation
132/33KV substation case study Presentation
 
Embedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoringEmbedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoring
 
ML Based Model for NIDS MSc Updated Presentation.v2.pptx
ML Based Model for NIDS MSc Updated Presentation.v2.pptxML Based Model for NIDS MSc Updated Presentation.v2.pptx
ML Based Model for NIDS MSc Updated Presentation.v2.pptx
 
5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...
5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...
5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...
 
sieving analysis and results interpretation
sieving analysis and results interpretationsieving analysis and results interpretation
sieving analysis and results interpretation
 

networks-lab-excercise4.pdf

  • 1. B.CHAT AIM: To implement a CHAT application using TCP Socket. Concept: 1. It uses TCP socket communication .We have a server as well as a client. 2. Both can be run in the same machine or different machines. If both are running in the machine, the address to be given at the client side is local host address. 3. If both are running in different machines, then in the client side we need to specify the ip address of machine in which server application is running. Program: Chatserver.java: import java.net.*; import java.io.*; public class chatserver { public static void main(String args[]) throws Exception { ServerSocket ss=new ServerSocket(2000); Socket sk=ss.accept(); BufferedReader cin=new BufferedReader(new InputStreamReader(sk.getInputStream())); PrintStream cout=new PrintStream(sk.getOutputStream()); BufferedReader stdin=new BufferedReader(new InputStreamReader(System.in)); String s; while ( true ) { s=cin.readLine(); if (s.equalsIgnoreCase("END")) { cout.println("BYE");
  • 2. break; } System. out.print("Client : "+s+"n"); System.out.print("Server : "); s=stdin.readLine(); cout.println(s); } ss.close(); sk.close(); cin.close(); cout.close(); stdin.close(); } } Chatclient.java import java.net.*; import java.io.*; public class chatclient { public static void main(String args[]) throws Exception { Socket sk=new Socket("127.0.0.1",2000); BufferedReader sin=new BufferedReader(new InputStreamReader(sk.getInputStream())); PrintStream sout=new PrintStream(sk.getOutputStream()); BufferedReader stdin=new BufferedReader(new InputStreamReader(System.in)); String s; while ( true ) { System.out.print("Client : "); s=stdin.readLine();
  • 3. sout.println(s); s=sin.readLine(); System.out.print("Server : "+s+"n"); if ( s.equalsIgnoreCase("BYE") ) break; } sk.close(); sin.close(); sout.close(); stdin.close(); } } OUTPUT: Server: E:nwlab>javac *.java E:nwlab>java chatserver Client : hi Server : hi Client: E:nwlab>java chatclient Client : hi Server : hi Client : Result: CHAT application using TCP Socket is implemented successfully.