SlideShare a Scribd company logo
LAPORAN TUGAS NETWORK PROGRAMMING
NAMA : RAHMAT HAMDANI
NIM: 201913002
Keterangan : Permasalahannyaterletakdisaatrun,chatyang dikirimolehclienttidakbisa
diketahui olehclientlain.Programtidakmendukunguntukmelakukanbroadcastantar client.
Server hanya bisa menerima satu client dan tidak menerima lebih dari satu client. Indikasi
permasalahannya terletak pada kekuatan jaringan yang tidak mendukung.
Source code
package syarifchatting;
import java.awt.Color;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.UnknownHostException;
import java.text.Normalizer.Form;
import java.util.Scanner;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JColorChooser;
import javax.swing.JOptionPane;
/**
* @author MhdSyarif
* Monday, 13 January 2014, 20 : 52 : 20 WIB
* Tugas III Matakulia Java2SE
* Mhd. Syarif | 49013075
* TKJMD - STEI - ITB
*/
public class Server extends javax.swing.JFrame implements Runnable{
int port=8080;
Socket client;
ServerSocket server;
BufferedReader Server_Reader, Client_Reader;
BufferedWriter Server_Writer, Client_Writer;
/**
* Creates new form Server
*/
public Server() {
super("www.mhdsyarif.com"); //SetTitle
initComponents();
//Menampilkan hasil ditengah window
java.awt.Dimension screenSize =
java.awt.Toolkit.getDefaultToolkit().getScreenSize();
java.awt.Dimension dialogSize = getSize();
setLocation((screenSize.width-
dialogSize.width)/2,(screenSize.height-dialogSize.height)/2);
getBackgroundColor();
}
//Pilihan ComboBox
private void getComboBox(){
if(ComboBox.getSelectedItem().equals("Server")){
ButtonOn.setText("On");
Username.setText("Server");
}else{
ButtonOn.setText("Connect");
Username.setText("Client");
}
}
//Koneksi client ke server
private void getClientConnec(){
try {
String ip = JOptionPane.showInputDialog(" Input IP Address");
client = new Socket(ip, port);
ComboBox.setEnabled(false);
ButtonOn.setText("Disconnect");
Server_Reader = new BufferedReader(new
InputStreamReader(client.getInputStream()));
Server_Writer = new BufferedWriter (new
OutputStreamWriter(client.getOutputStream()));
} catch (UnknownHostException ex) {
System.out.println("Accept Failed");
System.exit(-1);
} catch (IOException ex) {
Logger.getLogger(Form.class.getName()).log(Level.SEVERE, null,
ex);
}
}
private void getReadConnec(){
// try {
// try {
// try {
// server = new ServerSocket(port);
// this.setTitle("Please Wait");
// } catch (IOException ex) {
// System.out.println("Could not listen");
// System.exit(-1);
// }
// client = server.accept();
// this.setTitle("Connected" + client.getInetAddress());
// } catch (IOException ex) {
// System.out.println("Accept Failed");
// System.exit(-1);
// }
// Server_Reader = new BufferedReader(new
InputStreamReader(client.getInputStream()));
// Server_Writer = new BufferedWriter(new
OutputStreamWriter(client.getOutputStream()));
// } catch (IOException ex) {
// System.out.println("Read Failed");
// System.exit(-1);
// }
final int PORT = 8080;
try {
server = new ServerSocket(PORT);
} catch (IOException ex) {
Logger.getLogger(Server.class.getName()).log(Level.SEVERE,
null, ex);
}
System.out.println("Server started...");
System.out.println("Wating for clients...");
while (true) {
try {
client = server.accept();
} catch (IOException ex) {
Logger.getLogger(Server.class.getName()).log(Level.SEVERE,
null, ex);
}
Thread t = new Thread() {
public void run() {
try {
Server_Reader = new BufferedReader(new
InputStreamReader(client.getInputStream()));
} catch (IOException ex) {
Logger.getLogger(Server.class.getName()).log(Level.SEVERE, null, ex);
}
try {
Server_Writer = new BufferedWriter (new
OutputStreamWriter(client.getOutputStream()));
} catch (IOException ex) {
Logger.getLogger(Server.class.getName()).log(Level.SEVERE, null, ex);
}
try (
PrintWriter out = new
PrintWriter(client.getOutputStream(), true);
Scanner in = new Scanner(client.getInputStream());
) {
while (in.hasNextLine()) {
String input = in.nextLine();
if (input.equalsIgnoreCase("exit")) {
break;
}
System.out.println("Received radius from
client: " + input);
// double radius = Double.valueOf(input);
// double area = Math.PI* radius *radius ;
// out.println(area);
}
} catch (IOException e) { }
}
};
t.start();
}
}
private void getDisconnectedClient(){
try {
client.close();
Server_Reader.close();
Server_Writer.close();
ComboBox.setEnabled(true);
ButtonOn.setText("Connect");
} catch (IOException ex) {
Logger.getLogger(Form.class.getName()).log(Level.SEVERE, null,
ex);
}
}
private void getDisconnectedServer(){
try {
Server_Reader.close();
Server_Writer.close();
ButtonOn.setText("On");
this.setTitle("Disconected");
} catch (IOException ex) {
Logger.getLogger(Form.class.getName()).log(Level.SEVERE, null,
ex);
}
}
private void getButtonOn(){
if(ButtonOn.getText().equals("Connect"))
{
ButtonOn.setText("DIsconnect");
getClientConnec();
Thread thread1= new Thread(this);
Thread thread2= new Thread(this);
Thread thread3= new Thread(this);
Thread thread4= new Thread(this);
Thread thread5= new Thread(this);
Thread thread6= new Thread(this);
Thread thread7= new Thread(this);
Thread thread8= new Thread(this);
Thread thread9= new Thread(this);
Thread thread10= new Thread(this);
thread1.start();
thread2.start();
thread3.start();
thread4.start();
thread5.start();
thread6.start();
thread7.start();
thread8.start();
thread9.start();
thread10.start();
} else if(ComboBox.getSelectedItem().equals("Server")){
ButtonOn.setText("Off");
getReadConnec();
Thread thread1= new Thread(this);
Thread thread2= new Thread(this);
Thread thread3= new Thread(this);
Thread thread4= new Thread(this);
Thread thread5= new Thread(this);
Thread thread6= new Thread(this);
Thread thread7= new Thread(this);
Thread thread8= new Thread(this);
Thread thread9= new Thread(this);
Thread thread10= new Thread(this);
thread1.start();
thread2.start();
thread3.start();
thread4.start();
thread5.start();
thread6.start();
thread7.start();
thread8.start();
thread9.start();
thread10.start();
}else if(ButtonOn.getText().equals("Disconnect")){
getDisconnectedClient();
}else if(ButtonOn.getText().equals("Off")){
getDisconnectedServer();
}
}
private void getSend(){
try {
Server_Writer.write(Username.getText()+ ":
"+TextChat.getText());
Server_Writer.newLine();
Server_Writer.flush();
} catch (IOException ex) {
Logger.getLogger(Form.class.getName()).log(Level.SEVERE, null,
ex);
}
ListChat.add(Username.getText()+ ": " +TextChat.getText());
//jClient.setText(Username.getText());
TextChat.setText("");
}
//Background color
public void getBackgroundColor(){
Color c = JColorChooser.showDialog(null,"Background
Color",jPanel.getBackground());
jPanel.setBackground(c);
}
//Konfirmasi keluar
public void getExit(){
int confirm =JOptionPane.showConfirmDialog(this,"Are you sure will
exit this application ?","Exit
Application",JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE);
if (confirm == JOptionPane.YES_OPTION){
System.exit(0);
}
}

More Related Content

What's hot

Celery
CeleryCelery
Full Stack Unit Testing
Full Stack Unit TestingFull Stack Unit Testing
Full Stack Unit Testing
GlobalLogic Ukraine
 
Unit Testing Express and Koa Middleware in ES2015
Unit Testing Express and Koa Middleware in ES2015Unit Testing Express and Koa Middleware in ES2015
Unit Testing Express and Koa Middleware in ES2015
Morris Singer
 
Enhanced Web Service Testing: A Better Mock Structure
Enhanced Web Service Testing: A Better Mock StructureEnhanced Web Service Testing: A Better Mock Structure
Enhanced Web Service Testing: A Better Mock Structure
Salesforce Developers
 
Node.js System: The Approach
Node.js System: The ApproachNode.js System: The Approach
Node.js System: The Approach
Haci Murat Yaman
 
Advanced Jasmine - Front-End JavaScript Unit Testing
Advanced Jasmine - Front-End JavaScript Unit TestingAdvanced Jasmine - Front-End JavaScript Unit Testing
Advanced Jasmine - Front-End JavaScript Unit Testing
Lars Thorup
 
Monitoring patterns for mitigating technical risk
Monitoring patterns for  mitigating technical riskMonitoring patterns for  mitigating technical risk
Monitoring patterns for mitigating technical risk
Itai Frenkel
 
Unit Testing Express Middleware
Unit Testing Express MiddlewareUnit Testing Express Middleware
Unit Testing Express Middleware
Morris Singer
 
node.js errors
node.js errorsnode.js errors
node.js errors
LearningTech
 
The Ring programming language version 1.5.3 book - Part 89 of 184
The Ring programming language version 1.5.3 book - Part 89 of 184The Ring programming language version 1.5.3 book - Part 89 of 184
The Ring programming language version 1.5.3 book - Part 89 of 184
Mahmoud Samir Fayed
 
Ajax World Comet Talk
Ajax World Comet TalkAjax World Comet Talk
Ajax World Comet Talkrajivmordani
 
Clean code via dependency injection + guice
Clean code via dependency injection + guiceClean code via dependency injection + guice
Clean code via dependency injection + guice
Jordi Gerona
 
Unit testing CourseSites Apache Filter
Unit testing CourseSites Apache FilterUnit testing CourseSites Apache Filter
Unit testing CourseSites Apache Filter
Wayan Wira
 
Architecture for Massively Parallel HDL Simulations
Architecture for Massively Parallel HDL Simulations Architecture for Massively Parallel HDL Simulations
Architecture for Massively Parallel HDL Simulations DVClub
 
Csphtp1 22
Csphtp1 22Csphtp1 22
Csphtp1 22
HUST
 
PHPcon Poland - Static Analysis of PHP Code – How the Heck did I write so man...
PHPcon Poland - Static Analysis of PHP Code – How the Heck did I write so man...PHPcon Poland - Static Analysis of PHP Code – How the Heck did I write so man...
PHPcon Poland - Static Analysis of PHP Code – How the Heck did I write so man...
Rouven Weßling
 
Testing in android
Testing in androidTesting in android
Testing in android
jtrindade
 

What's hot (19)

Web
WebWeb
Web
 
Celery
CeleryCelery
Celery
 
Full Stack Unit Testing
Full Stack Unit TestingFull Stack Unit Testing
Full Stack Unit Testing
 
Unit Testing Express and Koa Middleware in ES2015
Unit Testing Express and Koa Middleware in ES2015Unit Testing Express and Koa Middleware in ES2015
Unit Testing Express and Koa Middleware in ES2015
 
Enhanced Web Service Testing: A Better Mock Structure
Enhanced Web Service Testing: A Better Mock StructureEnhanced Web Service Testing: A Better Mock Structure
Enhanced Web Service Testing: A Better Mock Structure
 
Node.js System: The Approach
Node.js System: The ApproachNode.js System: The Approach
Node.js System: The Approach
 
Advanced Jasmine - Front-End JavaScript Unit Testing
Advanced Jasmine - Front-End JavaScript Unit TestingAdvanced Jasmine - Front-End JavaScript Unit Testing
Advanced Jasmine - Front-End JavaScript Unit Testing
 
Monitoring patterns for mitigating technical risk
Monitoring patterns for  mitigating technical riskMonitoring patterns for  mitigating technical risk
Monitoring patterns for mitigating technical risk
 
Unit Testing Express Middleware
Unit Testing Express MiddlewareUnit Testing Express Middleware
Unit Testing Express Middleware
 
node.js errors
node.js errorsnode.js errors
node.js errors
 
The Ring programming language version 1.5.3 book - Part 89 of 184
The Ring programming language version 1.5.3 book - Part 89 of 184The Ring programming language version 1.5.3 book - Part 89 of 184
The Ring programming language version 1.5.3 book - Part 89 of 184
 
Ajax World Comet Talk
Ajax World Comet TalkAjax World Comet Talk
Ajax World Comet Talk
 
Clean code via dependency injection + guice
Clean code via dependency injection + guiceClean code via dependency injection + guice
Clean code via dependency injection + guice
 
Unit testing CourseSites Apache Filter
Unit testing CourseSites Apache FilterUnit testing CourseSites Apache Filter
Unit testing CourseSites Apache Filter
 
Architecture for Massively Parallel HDL Simulations
Architecture for Massively Parallel HDL Simulations Architecture for Massively Parallel HDL Simulations
Architecture for Massively Parallel HDL Simulations
 
Csphtp1 22
Csphtp1 22Csphtp1 22
Csphtp1 22
 
Qunit Java script Un
Qunit Java script UnQunit Java script Un
Qunit Java script Un
 
PHPcon Poland - Static Analysis of PHP Code – How the Heck did I write so man...
PHPcon Poland - Static Analysis of PHP Code – How the Heck did I write so man...PHPcon Poland - Static Analysis of PHP Code – How the Heck did I write so man...
PHPcon Poland - Static Analysis of PHP Code – How the Heck did I write so man...
 
Testing in android
Testing in androidTesting in android
Testing in android
 

Similar to Laporan tugas network programming

Server1
Server1Server1
Server1
FahriIrawan3
 
201913046 wahyu septiansyah network programing
201913046 wahyu septiansyah network programing201913046 wahyu septiansyah network programing
201913046 wahyu septiansyah network programing
wahyuseptiansyah
 
assigemt calculater.docx
assigemt calculater.docxassigemt calculater.docx
assigemt calculater.docx
zekfeker
 
I need you to modify and change the loop in this code without changing.docx
I need you to modify and change the loop in this code without changing.docxI need you to modify and change the loop in this code without changing.docx
I need you to modify and change the loop in this code without changing.docx
hendriciraida
 
Write a java program to create a program that outputs to the command l.docx
Write a java program to create a program that outputs to the command l.docxWrite a java program to create a program that outputs to the command l.docx
Write a java program to create a program that outputs to the command l.docx
lez31palka
 
Hi, I need some one to help me with Design a client-server Chat so.pdf
Hi, I need some one to help me with Design a client-server Chat so.pdfHi, I need some one to help me with Design a client-server Chat so.pdf
Hi, I need some one to help me with Design a client-server Chat so.pdf
fashiongallery1
 
Laporan multiclient chatting client server
Laporan multiclient chatting client serverLaporan multiclient chatting client server
Laporan multiclient chatting client servertrilestari08
 
I need an explaining for each step in this code and the reason of it-.docx
I need an explaining for each step in this code and the reason of it-.docxI need an explaining for each step in this code and the reason of it-.docx
I need an explaining for each step in this code and the reason of it-.docx
hendriciraida
 
Note Use Java Write a web server that is capable of processing only.pdf
Note Use Java Write a web server that is capable of processing only.pdfNote Use Java Write a web server that is capable of processing only.pdf
Note Use Java Write a web server that is capable of processing only.pdf
fatoryoutlets
 
Networking Core Concept
Networking Core ConceptNetworking Core Concept
Networking Core Concept
Rays Technologies
 
Client server part 12
Client server part 12Client server part 12
Client server part 12
fadlihulopi
 
networks-lab-excercise3.pdf
networks-lab-excercise3.pdfnetworks-lab-excercise3.pdf
networks-lab-excercise3.pdf
Jayaprasanna4
 
#3 (Multi Threads With TCP)
#3 (Multi Threads With TCP)#3 (Multi Threads With TCP)
#3 (Multi Threads With TCP)
Ghadeer AlHasan
 
Please look at the attach See.doc. I am getting this error all th.docx
Please look at the attach See.doc. I am getting this error all th.docxPlease look at the attach See.doc. I am getting this error all th.docx
Please look at the attach See.doc. I am getting this error all th.docx
randymartin91030
 
Include- Modularity using design patterns- Fault tolerance and Compone.pdf
Include- Modularity using design patterns- Fault tolerance and Compone.pdfInclude- Modularity using design patterns- Fault tolerance and Compone.pdf
Include- Modularity using design patterns- Fault tolerance and Compone.pdf
RyanF2PLeev
 
Distributed Objects and JAVA
Distributed Objects and JAVADistributed Objects and JAVA
Distributed Objects and JAVAelliando dias
 
Laporan multi client
Laporan multi clientLaporan multi client
Laporan multi clientichsanbarokah
 
Socket Programming
Socket ProgrammingSocket Programming
Socket Programming
Sivadon Chaisiri
 

Similar to Laporan tugas network programming (20)

Server1
Server1Server1
Server1
 
201913046 wahyu septiansyah network programing
201913046 wahyu septiansyah network programing201913046 wahyu septiansyah network programing
201913046 wahyu septiansyah network programing
 
assigemt calculater.docx
assigemt calculater.docxassigemt calculater.docx
assigemt calculater.docx
 
I need you to modify and change the loop in this code without changing.docx
I need you to modify and change the loop in this code without changing.docxI need you to modify and change the loop in this code without changing.docx
I need you to modify and change the loop in this code without changing.docx
 
Write a java program to create a program that outputs to the command l.docx
Write a java program to create a program that outputs to the command l.docxWrite a java program to create a program that outputs to the command l.docx
Write a java program to create a program that outputs to the command l.docx
 
Hi, I need some one to help me with Design a client-server Chat so.pdf
Hi, I need some one to help me with Design a client-server Chat so.pdfHi, I need some one to help me with Design a client-server Chat so.pdf
Hi, I need some one to help me with Design a client-server Chat so.pdf
 
Laporan multiclient chatting client server
Laporan multiclient chatting client serverLaporan multiclient chatting client server
Laporan multiclient chatting client server
 
I need an explaining for each step in this code and the reason of it-.docx
I need an explaining for each step in this code and the reason of it-.docxI need an explaining for each step in this code and the reason of it-.docx
I need an explaining for each step in this code and the reason of it-.docx
 
Note Use Java Write a web server that is capable of processing only.pdf
Note Use Java Write a web server that is capable of processing only.pdfNote Use Java Write a web server that is capable of processing only.pdf
Note Use Java Write a web server that is capable of processing only.pdf
 
Networking Core Concept
Networking Core ConceptNetworking Core Concept
Networking Core Concept
 
Client server part 12
Client server part 12Client server part 12
Client server part 12
 
networks-lab-excercise3.pdf
networks-lab-excercise3.pdfnetworks-lab-excercise3.pdf
networks-lab-excercise3.pdf
 
Network
NetworkNetwork
Network
 
#3 (Multi Threads With TCP)
#3 (Multi Threads With TCP)#3 (Multi Threads With TCP)
#3 (Multi Threads With TCP)
 
Please look at the attach See.doc. I am getting this error all th.docx
Please look at the attach See.doc. I am getting this error all th.docxPlease look at the attach See.doc. I am getting this error all th.docx
Please look at the attach See.doc. I am getting this error all th.docx
 
Include- Modularity using design patterns- Fault tolerance and Compone.pdf
Include- Modularity using design patterns- Fault tolerance and Compone.pdfInclude- Modularity using design patterns- Fault tolerance and Compone.pdf
Include- Modularity using design patterns- Fault tolerance and Compone.pdf
 
java sockets
 java sockets java sockets
java sockets
 
Distributed Objects and JAVA
Distributed Objects and JAVADistributed Objects and JAVA
Distributed Objects and JAVA
 
Laporan multi client
Laporan multi clientLaporan multi client
Laporan multi client
 
Socket Programming
Socket ProgrammingSocket Programming
Socket Programming
 

Recently uploaded

The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
joachimlavalley1
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
Fish and Chips - have they had their chips
Fish and Chips - have they had their chipsFish and Chips - have they had their chips
Fish and Chips - have they had their chips
GeoBlogs
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
Excellence Foundation for South Sudan
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Tamralipta Mahavidyalaya
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
RaedMohamed3
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdfESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
Fundacja Rozwoju Społeczeństwa Przedsiębiorczego
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
AzmatAli747758
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
MIRIAMSALINAS13
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
Anna Sz.
 
Basic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersBasic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumers
PedroFerreira53928
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 

Recently uploaded (20)

The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
Fish and Chips - have they had their chips
Fish and Chips - have they had their chipsFish and Chips - have they had their chips
Fish and Chips - have they had their chips
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdfESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
 
Basic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersBasic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumers
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 

Laporan tugas network programming

  • 1. LAPORAN TUGAS NETWORK PROGRAMMING NAMA : RAHMAT HAMDANI NIM: 201913002 Keterangan : Permasalahannyaterletakdisaatrun,chatyang dikirimolehclienttidakbisa diketahui olehclientlain.Programtidakmendukunguntukmelakukanbroadcastantar client.
  • 2. Server hanya bisa menerima satu client dan tidak menerima lebih dari satu client. Indikasi permasalahannya terletak pada kekuatan jaringan yang tidak mendukung. Source code package syarifchatting; import java.awt.Color; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.net.ServerSocket; import java.net.Socket; import java.net.UnknownHostException; import java.text.Normalizer.Form; import java.util.Scanner; import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.JColorChooser; import javax.swing.JOptionPane; /** * @author MhdSyarif * Monday, 13 January 2014, 20 : 52 : 20 WIB * Tugas III Matakulia Java2SE * Mhd. Syarif | 49013075 * TKJMD - STEI - ITB */
  • 3. public class Server extends javax.swing.JFrame implements Runnable{ int port=8080; Socket client; ServerSocket server; BufferedReader Server_Reader, Client_Reader; BufferedWriter Server_Writer, Client_Writer; /** * Creates new form Server */ public Server() { super("www.mhdsyarif.com"); //SetTitle initComponents(); //Menampilkan hasil ditengah window java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize(); java.awt.Dimension dialogSize = getSize(); setLocation((screenSize.width- dialogSize.width)/2,(screenSize.height-dialogSize.height)/2); getBackgroundColor(); } //Pilihan ComboBox private void getComboBox(){ if(ComboBox.getSelectedItem().equals("Server")){ ButtonOn.setText("On"); Username.setText("Server"); }else{ ButtonOn.setText("Connect"); Username.setText("Client"); } } //Koneksi client ke server private void getClientConnec(){ try { String ip = JOptionPane.showInputDialog(" Input IP Address"); client = new Socket(ip, port); ComboBox.setEnabled(false); ButtonOn.setText("Disconnect"); Server_Reader = new BufferedReader(new InputStreamReader(client.getInputStream())); Server_Writer = new BufferedWriter (new OutputStreamWriter(client.getOutputStream())); } catch (UnknownHostException ex) { System.out.println("Accept Failed"); System.exit(-1); } catch (IOException ex) { Logger.getLogger(Form.class.getName()).log(Level.SEVERE, null, ex); } } private void getReadConnec(){ // try { // try { // try { // server = new ServerSocket(port); // this.setTitle("Please Wait"); // } catch (IOException ex) {
  • 4. // System.out.println("Could not listen"); // System.exit(-1); // } // client = server.accept(); // this.setTitle("Connected" + client.getInetAddress()); // } catch (IOException ex) { // System.out.println("Accept Failed"); // System.exit(-1); // } // Server_Reader = new BufferedReader(new InputStreamReader(client.getInputStream())); // Server_Writer = new BufferedWriter(new OutputStreamWriter(client.getOutputStream())); // } catch (IOException ex) { // System.out.println("Read Failed"); // System.exit(-1); // } final int PORT = 8080; try { server = new ServerSocket(PORT); } catch (IOException ex) { Logger.getLogger(Server.class.getName()).log(Level.SEVERE, null, ex); } System.out.println("Server started..."); System.out.println("Wating for clients..."); while (true) { try { client = server.accept(); } catch (IOException ex) { Logger.getLogger(Server.class.getName()).log(Level.SEVERE, null, ex); } Thread t = new Thread() { public void run() { try { Server_Reader = new BufferedReader(new InputStreamReader(client.getInputStream())); } catch (IOException ex) { Logger.getLogger(Server.class.getName()).log(Level.SEVERE, null, ex); } try { Server_Writer = new BufferedWriter (new OutputStreamWriter(client.getOutputStream())); } catch (IOException ex) { Logger.getLogger(Server.class.getName()).log(Level.SEVERE, null, ex); } try ( PrintWriter out = new PrintWriter(client.getOutputStream(), true); Scanner in = new Scanner(client.getInputStream()); ) {
  • 5. while (in.hasNextLine()) { String input = in.nextLine(); if (input.equalsIgnoreCase("exit")) { break; } System.out.println("Received radius from client: " + input); // double radius = Double.valueOf(input); // double area = Math.PI* radius *radius ; // out.println(area); } } catch (IOException e) { } } }; t.start(); } } private void getDisconnectedClient(){ try { client.close(); Server_Reader.close(); Server_Writer.close(); ComboBox.setEnabled(true); ButtonOn.setText("Connect"); } catch (IOException ex) { Logger.getLogger(Form.class.getName()).log(Level.SEVERE, null, ex); } } private void getDisconnectedServer(){ try { Server_Reader.close(); Server_Writer.close(); ButtonOn.setText("On"); this.setTitle("Disconected"); } catch (IOException ex) { Logger.getLogger(Form.class.getName()).log(Level.SEVERE, null, ex); } } private void getButtonOn(){ if(ButtonOn.getText().equals("Connect")) { ButtonOn.setText("DIsconnect"); getClientConnec(); Thread thread1= new Thread(this); Thread thread2= new Thread(this); Thread thread3= new Thread(this); Thread thread4= new Thread(this); Thread thread5= new Thread(this); Thread thread6= new Thread(this); Thread thread7= new Thread(this); Thread thread8= new Thread(this); Thread thread9= new Thread(this); Thread thread10= new Thread(this); thread1.start(); thread2.start();
  • 6. thread3.start(); thread4.start(); thread5.start(); thread6.start(); thread7.start(); thread8.start(); thread9.start(); thread10.start(); } else if(ComboBox.getSelectedItem().equals("Server")){ ButtonOn.setText("Off"); getReadConnec(); Thread thread1= new Thread(this); Thread thread2= new Thread(this); Thread thread3= new Thread(this); Thread thread4= new Thread(this); Thread thread5= new Thread(this); Thread thread6= new Thread(this); Thread thread7= new Thread(this); Thread thread8= new Thread(this); Thread thread9= new Thread(this); Thread thread10= new Thread(this); thread1.start(); thread2.start(); thread3.start(); thread4.start(); thread5.start(); thread6.start(); thread7.start(); thread8.start(); thread9.start(); thread10.start(); }else if(ButtonOn.getText().equals("Disconnect")){ getDisconnectedClient(); }else if(ButtonOn.getText().equals("Off")){ getDisconnectedServer(); } } private void getSend(){ try { Server_Writer.write(Username.getText()+ ": "+TextChat.getText()); Server_Writer.newLine(); Server_Writer.flush(); } catch (IOException ex) { Logger.getLogger(Form.class.getName()).log(Level.SEVERE, null, ex); } ListChat.add(Username.getText()+ ": " +TextChat.getText()); //jClient.setText(Username.getText()); TextChat.setText(""); } //Background color public void getBackgroundColor(){ Color c = JColorChooser.showDialog(null,"Background Color",jPanel.getBackground()); jPanel.setBackground(c); } //Konfirmasi keluar
  • 7. public void getExit(){ int confirm =JOptionPane.showConfirmDialog(this,"Are you sure will exit this application ?","Exit Application",JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE); if (confirm == JOptionPane.YES_OPTION){ System.exit(0); } }