Program ini membuat browser sederhana menggunakan bahasa pemrograman Java yang memungkinkan pengguna untuk memilih antara membuka URL, mencari di Google, mencari gambar di Google, menerjemahkan kata, mencari berita, dan keluar dari program. Program ini menggunakan fitur Desktop.browse untuk membuka halaman web yang diinginkan pengguna sesuai dengan pilihan yang dipilih.
This document describes a multi-client chat client-server application created using Java socket programming. It includes the code for the ChatServer.java and ChatClient.java classes. The ChatServer class handles multiple client connections and broadcasts messages to all connected clients. The ChatClient class represents the graphical client interface that connects to the server and allows users to send and receive chat messages. The application allows for multiple clients to simultaneously chat by connecting to a central chat server.
This document describes a Java program that implements an information server and client. The server program listens for connections on port 50000 and responds to client commands with information like the current time or network details. The client program connects to the server and allows the user to enter commands like TIME, NET, or QUIT to retrieve data from the server and then closes the connection. Code snippets are provided for both the server and client programs along with descriptions of how they work and example outputs.
Program Java sederhana untuk mengambil nama komputer berdasarkan alamat IP dengan menggunakan package java.net dan method getLocalHost() dan getHostName(). Program mencetak nama komputer yang dijalankan.
This document describes a Java program called getIP.java that is used to retrieve the IP address of the local computer. The program imports the necessary Java networking classes, gets the local host InetAddress, and then retrieves and prints out the byte array representation of the IP address, separating each byte value with a period. When run, the program outputs the IP address of the local computer.
Program ini membuat browser sederhana menggunakan bahasa pemrograman Java yang memungkinkan pengguna untuk memilih antara membuka URL, mencari di Google, mencari gambar di Google, menerjemahkan kata, mencari berita, dan keluar dari program. Program ini menggunakan fitur Desktop.browse untuk membuka halaman web yang diinginkan pengguna sesuai dengan pilihan yang dipilih.
This document describes a multi-client chat client-server application created using Java socket programming. It includes the code for the ChatServer.java and ChatClient.java classes. The ChatServer class handles multiple client connections and broadcasts messages to all connected clients. The ChatClient class represents the graphical client interface that connects to the server and allows users to send and receive chat messages. The application allows for multiple clients to simultaneously chat by connecting to a central chat server.
This document describes a Java program that implements an information server and client. The server program listens for connections on port 50000 and responds to client commands with information like the current time or network details. The client program connects to the server and allows the user to enter commands like TIME, NET, or QUIT to retrieve data from the server and then closes the connection. Code snippets are provided for both the server and client programs along with descriptions of how they work and example outputs.
Program Java sederhana untuk mengambil nama komputer berdasarkan alamat IP dengan menggunakan package java.net dan method getLocalHost() dan getHostName(). Program mencetak nama komputer yang dijalankan.
This document describes a Java program called getIP.java that is used to retrieve the IP address of the local computer. The program imports the necessary Java networking classes, gets the local host InetAddress, and then retrieves and prints out the byte array representation of the IP address, separating each byte value with a period. When run, the program outputs the IP address of the local computer.
1. Program Server dan Client
Dengan Menggunakan Bahasa Pemrograman Java
Oleh :
TRI LESTARI
(061130701310)
6CD
JURUSAN TEKNIK KOMPUTER
POLITEKNIK NEGERI SRIWIJAYA
PALEMBANG
2014
2. PROGRAM SERVER DAN CLIENT DENGAN
MENGGUNAKAN BAHASA PEMROGRAMAN JAVA
Server.java
import java.io.*;
import java.net.*;
import java.util.*;
public class Server{
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:
MultiEchoClient.java
import java.net.*;
import java.io.*;
import java.util.*;
public class MultiEchoClient {
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.