SlideShare a Scribd company logo
1 of 7
TUGAS
Melihat Info Server dan Info Client Menggunakan
Bahasa Pemrograman Java
Oleh :
M. Ichsan Barokah
061130701305
6CD
JURUSAN TEKNIK KOMPUTER
POLITEKNIK NEGERI SRIWIJAYA
PALEMBANG
Pada bagian kali ini, Program untuk mengetahui info server dan info client
suatu komputer. Berikut adalah listing codenya dan eksekusi dari program yang
telah dibuat.
A) infoserver.java
import java.io.*;
import java.net.*;
import java.util.*;
public class infoserver {
private final int INFO_PORT=50000;
private String datafromClient;
public infoserver() {
BufferedReader inFromClient;
DataOutputStream outToClient;
Socket serverSocket;
try {
ServerSocket infoserver =
new ServerSocket(INFO_PORT);
System.out.println("Server siap...");
while (true){
serverSocket = infoserver.accept();
System.out.println("Ada client" +
"yang terkoneksi!");
inFromClient =
new BufferedReader(
new InputStreamReader(
serverSocket.getInputStream()));
outToClient =
new DataOutputStream(
serverSocket.getOutputStream());
outToClient.writeBytes("InfoServer versi 0.1n"+
"hanya untuk testing..n"+
"Silahkan berikan perintah TIME|NET|QUITn");
boolean isQUIT = false;
while (!isQUIT) {
datafromClient = inFromClient.readLine();
if (datafromClient.startsWith("TIME")){
outToClient.writeBytes(new
Date().toString() + "n");
} else if (datafromClient.startsWith("NET")){
outToClient.writeBytes(
InetAddress.getByName("localhost").toString()+
"n");
} else if (datafromClient.startsWith("QUIT"))
{
isQUIT = true;
}
}
outToClient.close();
inFromClient.close();
serverSocket.close();
System.out.println("Koneksi client sudah tertutup..");
}
}
catch (IOException ioe) {
System.out.print("error:" + ioe);
}
catch (Exception e) {
System.out.print("error:" + e);
}
}
public static void main(String[]args) {
new infoserver();
}
}
Jalankan program yang telah dibuat maka tampilan server akan seperti
berikut:
B) InfoClient.java
import java.net.*;
import java.io.*;
import java.util.*;
public class InfoClient {
private final int INFO_PORT=50000;
private final String TargetHost = "localhost";
private final String QUIT = "QUIT";
public InfoClient() {
try {
BufferedReader inFromUser =
new BufferedReader(new
InputStreamReader(System.in));
Socket clientSocket = new
Socket(TargetHost, INFO_PORT);
DataOutputStream outToServer =
new DataOutputStream(
clientSocket.getOutputStream());
BufferedReader inFromServer =
new BufferedReader(
new InputStreamReader(
clientSocket.getInputStream()));
System.out.println(inFromServer.readLine());
System.out.println(inFromServer.readLine());
System.out.println(inFromServer.readLine());
System.out.println("");
boolean isQuit = false;
while (!isQuit) {
System.out.print("Ketikkan Perintah Anda : ");
String cmd = inFromUser.readLine();
cmd = cmd.toUpperCase();
if (cmd.equals(QUIT)) {
isQuit = true;
}
outToServer.writeBytes(cmd + "n");
String result = inFromServer.readLine();
System.out.println("Dari Server: " + result);
}
outToServer.close();
inFromServer.close();
clientSocket.close();
}
catch (IOException ioe) {
System.out.println("Error:" + ioe);
}
catch (Exception e) {
System.out.println("Error:" + e);
}
}
public static void main(String[]args) {
new InfoClient();
}
}
Kemudian running juga program InfoClient.java dengan cara klik ctrl+1 lalu
ctrl+2, maka tampilan akan seperti berikut:
Lihat ke bagian jendela server. Ketika Client telah terkoneksi dengan server,
maka tampilan akan seperti berikut:
Lalu kembali ke jendela Client untuk memilih perintah. Masukkan perintah
yang anda ingin, seperti ini untuk melihat waktu, dan jaringan yang terdapat di
PC/Laptop anda.

More Related Content

Featured

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 

Featured (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

Laporan info server dan infoclient

  • 1. TUGAS Melihat Info Server dan Info Client Menggunakan Bahasa Pemrograman Java Oleh : M. Ichsan Barokah 061130701305 6CD JURUSAN TEKNIK KOMPUTER POLITEKNIK NEGERI SRIWIJAYA PALEMBANG
  • 2. Pada bagian kali ini, Program untuk mengetahui info server dan info client suatu komputer. Berikut adalah listing codenya dan eksekusi dari program yang telah dibuat. A) infoserver.java import java.io.*; import java.net.*; import java.util.*; public class infoserver { private final int INFO_PORT=50000; private String datafromClient; public infoserver() { BufferedReader inFromClient; DataOutputStream outToClient; Socket serverSocket; try { ServerSocket infoserver = new ServerSocket(INFO_PORT); System.out.println("Server siap..."); while (true){ serverSocket = infoserver.accept(); System.out.println("Ada client" + "yang terkoneksi!"); inFromClient = new BufferedReader( new InputStreamReader( serverSocket.getInputStream())); outToClient = new DataOutputStream( serverSocket.getOutputStream()); outToClient.writeBytes("InfoServer versi 0.1n"+
  • 3. "hanya untuk testing..n"+ "Silahkan berikan perintah TIME|NET|QUITn"); boolean isQUIT = false; while (!isQUIT) { datafromClient = inFromClient.readLine(); if (datafromClient.startsWith("TIME")){ outToClient.writeBytes(new Date().toString() + "n"); } else if (datafromClient.startsWith("NET")){ outToClient.writeBytes( InetAddress.getByName("localhost").toString()+ "n"); } else if (datafromClient.startsWith("QUIT")) { isQUIT = true; } } outToClient.close(); inFromClient.close(); serverSocket.close(); System.out.println("Koneksi client sudah tertutup.."); } } catch (IOException ioe) { System.out.print("error:" + ioe); } catch (Exception e) { System.out.print("error:" + e); } } public static void main(String[]args) { new infoserver(); } }
  • 4. Jalankan program yang telah dibuat maka tampilan server akan seperti berikut: B) InfoClient.java import java.net.*; import java.io.*; import java.util.*; public class InfoClient { private final int INFO_PORT=50000; private final String TargetHost = "localhost"; private final String QUIT = "QUIT"; public InfoClient() { try { BufferedReader inFromUser = new BufferedReader(new InputStreamReader(System.in)); Socket clientSocket = new Socket(TargetHost, INFO_PORT); DataOutputStream outToServer = new DataOutputStream(
  • 5. clientSocket.getOutputStream()); BufferedReader inFromServer = new BufferedReader( new InputStreamReader( clientSocket.getInputStream())); System.out.println(inFromServer.readLine()); System.out.println(inFromServer.readLine()); System.out.println(inFromServer.readLine()); System.out.println(""); boolean isQuit = false; while (!isQuit) { System.out.print("Ketikkan Perintah Anda : "); String cmd = inFromUser.readLine(); cmd = cmd.toUpperCase(); if (cmd.equals(QUIT)) { isQuit = true; } outToServer.writeBytes(cmd + "n"); String result = inFromServer.readLine(); System.out.println("Dari Server: " + result); } outToServer.close(); inFromServer.close(); clientSocket.close(); } catch (IOException ioe) { System.out.println("Error:" + ioe); } catch (Exception e) { System.out.println("Error:" + e); } }
  • 6. public static void main(String[]args) { new InfoClient(); } } Kemudian running juga program InfoClient.java dengan cara klik ctrl+1 lalu ctrl+2, maka tampilan akan seperti berikut: Lihat ke bagian jendela server. Ketika Client telah terkoneksi dengan server, maka tampilan akan seperti berikut:
  • 7. Lalu kembali ke jendela Client untuk memilih perintah. Masukkan perintah yang anda ingin, seperti ini untuk melihat waktu, dan jaringan yang terdapat di PC/Laptop anda.