際際滷

際際滷Share a Scribd company logo
Program Info Server dan info
client dengan menggunakan
bahasa Pemrograman Java
Oleh :
TRI LESTARI
(061130701310)
6CD
JURUSAN TEKNIK KOMPUTER
POLITEKNIK NEGERI SRIWIJAYA
PALEMBANG
2014
PROGRAM INFO SERVER DAN INFO CLIENT DENGAN
MENGGUNAKAN BAHASA PEMROGRAMAN JAVA
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();
}
}
Setelah di compile, maka hasilnya dapat dilihat seperti dibawah ini:
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();
}
}
Setelah di compile, maka hasilnya dapat dilihat seperti dibawah ini:
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

Viewers also liked (20)

Jaringan komputer topologi
Jaringan komputer topologiJaringan komputer topologi
Jaringan komputer topologi
jamban22
Katy perry
Katy perryKaty perry
Katy perry
kjgarnett3244
Engtest  47Engtest  47
Engtest 47
Wanachon Boonmee
犢犖犖劇犖犖犖犖迦牽犢犖犢犖犖巌犢犖犖犖犢犢犖犢犖犖犖犖犖犖園犢犖犖朽権犖犖犖園犖 犖
犢犖犖劇犖犖犖犖迦牽犢犖犢犖犖巌犢犖犖犖犢犢犖犢犖犖犖犖犖犖園犢犖犖朽権犖犖犖園犖 犖犢犖犖劇犖犖犖犖迦牽犢犖犢犖犖巌犢犖犖犖犢犢犖犢犖犖犖犖犖犖園犢犖犖朽権犖犖犖園犖 犖
犢犖犖劇犖犖犖犖迦牽犢犖犢犖犖巌犢犖犖犖犢犢犖犢犖犖犖犖犖犖園犢犖犖朽権犖犖犖園犖 犖
Kaembum Soraya
256.no + bullying256.no + bullying
256.no + bullying
dec-admin
ECC Cloud and Security
ECC Cloud and SecurityECC Cloud and Security
ECC Cloud and Security
Erlach Computer Consulting
veroca is finally educated
veroca is finally educatedveroca is finally educated
veroca is finally educated
alumnos5to
Front cover drafts
Front cover draftsFront cover drafts
Front cover drafts
bethanyhill1998
soul James Brown  :)soul James Brown  :)
soul James Brown :)
anadelcerro
Seguridad inform叩ticaSeguridad inform叩tica
Seguridad inform叩tica
diegoatleti9
Multic
MulticMultic
Multic
Eka Agus
01 web-apps
01 web-apps01 web-apps
01 web-apps
snopteck
Redes linux con tcpip   pat eylerRedes linux con tcpip   pat eyler
Redes linux con tcpip pat eyler
Toni Horrach
Elementos de un blog 2Elementos de un blog 2
Elementos de un blog 2
omargarcia1444
Instrumento de evaluaci坦nInstrumento de evaluaci坦n
Instrumento de evaluaci坦n
Alexia Lecuona
Dibujo T辿cnico I. T6 T7 ConceptosDibujo T辿cnico I. T6 T7 Conceptos
Dibujo T辿cnico I. T6 T7 Conceptos
Fernando C.
Virus y antivirusVirus y antivirus
Virus y antivirus
cristian camilo
Ruben martins 30 slide presentation
Ruben martins 30 slide presentationRuben martins 30 slide presentation
Ruben martins 30 slide presentation
Rubenm2
TIK BAB 1
TIK BAB 1TIK BAB 1
TIK BAB 1
OsHz
Jaringan komputer topologi
Jaringan komputer topologiJaringan komputer topologi
Jaringan komputer topologi
jamban22
Engtest  47Engtest  47
Engtest 47
Wanachon Boonmee
犢犖犖劇犖犖犖犖迦牽犢犖犢犖犖巌犢犖犖犖犢犢犖犢犖犖犖犖犖犖園犢犖犖朽権犖犖犖園犖 犖
犢犖犖劇犖犖犖犖迦牽犢犖犢犖犖巌犢犖犖犖犢犢犖犢犖犖犖犖犖犖園犢犖犖朽権犖犖犖園犖 犖犢犖犖劇犖犖犖犖迦牽犢犖犢犖犖巌犢犖犖犖犢犢犖犢犖犖犖犖犖犖園犢犖犖朽権犖犖犖園犖 犖
犢犖犖劇犖犖犖犖迦牽犢犖犢犖犖巌犢犖犖犖犢犢犖犢犖犖犖犖犖犖園犢犖犖朽権犖犖犖園犖 犖
Kaembum Soraya
256.no + bullying256.no + bullying
256.no + bullying
dec-admin
veroca is finally educated
veroca is finally educatedveroca is finally educated
veroca is finally educated
alumnos5to
soul James Brown  :)soul James Brown  :)
soul James Brown :)
anadelcerro
Seguridad inform叩ticaSeguridad inform叩tica
Seguridad inform叩tica
diegoatleti9
01 web-apps
01 web-apps01 web-apps
01 web-apps
snopteck
Redes linux con tcpip   pat eylerRedes linux con tcpip   pat eyler
Redes linux con tcpip pat eyler
Toni Horrach
Elementos de un blog 2Elementos de un blog 2
Elementos de un blog 2
omargarcia1444
Instrumento de evaluaci坦nInstrumento de evaluaci坦n
Instrumento de evaluaci坦n
Alexia Lecuona
Dibujo T辿cnico I. T6 T7 ConceptosDibujo T辿cnico I. T6 T7 Conceptos
Dibujo T辿cnico I. T6 T7 Conceptos
Fernando C.
Virus y antivirusVirus y antivirus
Virus y antivirus
cristian camilo
Ruben martins 30 slide presentation
Ruben martins 30 slide presentationRuben martins 30 slide presentation
Ruben martins 30 slide presentation
Rubenm2
TIK BAB 1
TIK BAB 1TIK BAB 1
TIK BAB 1
OsHz

More from trilestari08 (9)

Laporan program browser
Laporan program browserLaporan program browser
Laporan program browser
trilestari08
Laporan multiclient chatting client server
Laporan multiclient chatting client serverLaporan multiclient chatting client server
Laporan multiclient chatting client server
trilestari08
Laporan chatting server dan client
Laporan chatting server dan clientLaporan chatting server dan client
Laporan chatting server dan client
trilestari08
Laporan info server dan info client
Laporan info server dan info clientLaporan info server dan info client
Laporan info server dan info client
trilestari08
Laporan get nama
Laporan get namaLaporan get nama
Laporan get nama
trilestari08
Laporan Chatting Server dan Client
Laporan Chatting Server dan ClientLaporan Chatting Server dan Client
Laporan Chatting Server dan Client
trilestari08
Laporan ambil nama
Laporan ambil namaLaporan ambil nama
Laporan ambil nama
trilestari08
Laporan Ambil IP
Laporan Ambil IPLaporan Ambil IP
Laporan Ambil IP
trilestari08
Laporan program browser
Laporan program browserLaporan program browser
Laporan program browser
trilestari08
Laporan multiclient chatting client server
Laporan multiclient chatting client serverLaporan multiclient chatting client server
Laporan multiclient chatting client server
trilestari08
Laporan chatting server dan client
Laporan chatting server dan clientLaporan chatting server dan client
Laporan chatting server dan client
trilestari08
Laporan info server dan info client
Laporan info server dan info clientLaporan info server dan info client
Laporan info server dan info client
trilestari08
Laporan get nama
Laporan get namaLaporan get nama
Laporan get nama
trilestari08
Laporan Chatting Server dan Client
Laporan Chatting Server dan ClientLaporan Chatting Server dan Client
Laporan Chatting Server dan Client
trilestari08
Laporan ambil nama
Laporan ambil namaLaporan ambil nama
Laporan ambil nama
trilestari08
Laporan Ambil IP
Laporan Ambil IPLaporan Ambil IP
Laporan Ambil IP
trilestari08

Laporan Info Server dan Info Client

  • 1. Program Info Server dan info client dengan menggunakan bahasa Pemrograman Java Oleh : TRI LESTARI (061130701310) 6CD JURUSAN TEKNIK KOMPUTER POLITEKNIK NEGERI SRIWIJAYA PALEMBANG 2014
  • 2. PROGRAM INFO SERVER DAN INFO CLIENT DENGAN MENGGUNAKAN BAHASA PEMROGRAMAN JAVA 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(
  • 3. 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) {
  • 4. System.out.print("error:" + ioe); } catch (Exception e) { System.out.print("error:" + e); } } public static void main(String[]args) { new infoserver(); } } Setelah di compile, maka hasilnya dapat dilihat seperti dibawah ini: 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";
  • 5. 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();
  • 6. 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(); } } Setelah di compile, maka hasilnya dapat dilihat seperti dibawah ini:
  • 7. 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.