Showing posts with label client server. Show all posts
Showing posts with label client server. Show all posts

Wednesday, June 12, 2013

sistem terdistribusi

Sistem Terdistribusi adalah Sekumpulan komputer otonom yang terhubung ke suatu jaringan, dimana bagi pengguna sistem terlihat sebagai satu komputer. Maksud komputer otonomi adalah walaupun komputer tidak terhubung ke jaringan, komputer tersebut tetap data berjalan.

Dengan menjalankan sistem terdistribusi, komputer dapat melakukan :
  1. Koordinasi Aktifitas
  2. Berbagi sumber daya : hardware, software dan data
Dengan definisi tersebut diatas maka internet sesungguhnya bukanlah suatu sistem terdistribusi, melainkan infrastruktur dimana sistem terdistribusi dapat di aplikasikan pada jaringan tersebut.

Contoh Sistem Terdistribusi:
  • Sistem Telepon :ISDN, PSTN
  • Manajemen Jaringan : Adminstrasi ke sumber jaringan
 Keuntungan Sistem Terdistribusi
  • Performance : Kumpulan dari beberapa prosesor akan memberikan kinerja yang lebih baik dari pada komputer yang terpusat. Begitu juga kalau dilihat dari sisi biaya.- Distribution 
  • Reliability (Fault tolerance) : apabila salah satu komponen terjadi kerusakan, sistem tetap dapat berjalan 
  • Incremental Growth : Mudah dalam melakukan penambahan komputer/komponen 
  • Sharing Data/Resources : Berbagi data adalah salah satu hal yang pokok pada kebanyakan aplikasi.
 Kelemahan pada sistem terdistribusi :
  • Kesulitan dalam membangun perangkat lunak . Kesulitan yang akan dihadapi antara lain : bahasa pemrograman yang harus dipakai, sistem operasi dll.
  • Masalah Jaringan : Karena sistem terdistribusi di implementasikan dalam jaringan komputer, maka isu2 yang berkaitan dengan jaringan komputer akan menjadi pertimbangan utama dalam merancang dan mengimplementasikan sistem.
  • Masalah Keamanan : Karena pada sistem terdistribusi berbagi data/sumber daya merupakan hal yang mutlak, maka muncul masalah2 yang berkaitan dengan keamanan data dll.
Karakteristik Sistem Terdistribusi
  1. Transparency (Kejelasan)
  2. Communication (Komunikasi)
  3. Performance & Scalability (Kinerja dan Ruang Lingkup)
  4. Heterogeneity (Keanekaragaman)
  5. Opennes (Keterbukaan)
  6. Reliability & Fault Tolerancy (Kehandalan dan Toleransi Kegagalan)
  7. Security (Kemanan)
 Model dalam sistem terdistribusi :
  • Model Arsitektur (Architectural Models)
  • Model Interaksi (Interaction Models)
  • Model Kegagalan (Failure Models)


»»  READMORE...

game domino menggunakan java

berikut coding game domino:

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Domino;
import java.util.*;
import javax.swing.JOptionPane;
class Variables {
   static Dice dice=new Dice (49);
   static tiles tile=new tiles();
   static String [] character=new String[3];
   static int charcount=0;
   static int player1[][]=new int[2][49];
   static int player2[][]=new int[2][49];
   static int dicevalue;
   static boolean check;
   static boolean checkroll;
   static boolean checkroll1;
   static boolean checkgame=true;
   static int highhead1=0;
   static int highhead2=0;
   static int hightail1=0;
   static int hightail2=0;
   static int interval[][]=new int[2][98];
   static int x2=49;
   static int y2=49;
   static int xx2=49;
   static int yy2=49;
   static int toplace;
   static int counter1;
   static int counterplayer1;
   static int counterplayer2;
   static int temp;
}
 class Dice {
    Random r =new Random();
    int sides;
 //constructor
    public Dice(int s){
       sides = s;
    }
 //roll method depending on sides up there
    public int roll(){
    return r.nextInt(sides);
    }
}
 class tiles {
  static int headcount=0;
  static int tailcount=0;
  static int a=0;
  static int b=0;
  int handler[][]=new int [2][49];
    public void dominotiles(){
        for(int x=0;x<49;x++){
            for(int y=0; y<2; y++){
                if(y==0){
                    if(headcount==7){
                        headcount=0;
                        a=a+1;
                    }
                    if(headcount<=6){
                    handler[y][x]=a;
                    headcount=headcount+1;
                    }
                }
                else {
                    if(tailcount==7){
                        tailcount=0;
                    }
                    if(tailcount<=6){
                     handler[y][x]=tailcount;
                    tailcount=tailcount+1;
                    }
                }
            }
        }
    }
}
public class  Gapleh extends Variables {
    public static void main(String[]args){
      tile.dominotiles();
      for(int x=0;x<49;x++){
        for(int y=0; y<2; y++){
                    player1[y][x]=7;
                    player2[y][x]=7;
        }
      }
     for(int x=0;x<98;x++)
        for(int y=0;y<2;y++){
                interval[y][x]=7;
        }
      newCharacter();
      newCharacter();
      JOptionPane.showMessageDialog(null,character[0]+" Di Kocok Secara Acak");
      for(int x=0;x<7;x++){
          check=true;
        while(check){
           dicevalue=dice.roll();
            if(tile. handler[0][dicevalue]<7 && tile. handler[1][dicevalue]<7){
                player1[0][dicevalue]=tile. handler[0][dicevalue];
                player1[1][dicevalue]=tile. handler[1][dicevalue];
                tile. handler[0][dicevalue]=7;
                tile. handler[1][dicevalue]=7;
                if(highhead1<player1[0][dicevalue]){
                    highhead1=player1[0][dicevalue];
                    hightail1=player1[1][dicevalue];
                }
                check=false;
            }
        }
      }
            System.out.println(character[0]+"'s tiles");
            for(int x=0;x<49;x++){
                    if(player1[0][x]<7&&player1[1][x]<7){
                        System.out.print("("+player1[0][x]+","+player1[1][x]+")");
                        System.out.println();
                    }
            }
      JOptionPane.showMessageDialog(null,character[1]+" Di Kocok Secara Acak");
      for(int x=0;x<7;x++){
          check=true;
        while(check){
           dicevalue=dice.roll();
            if(tile. handler[0][dicevalue]<7 && tile. handler[1][dicevalue]<7){
                player2[0][dicevalue]=tile. handler[0][dicevalue];
                player2[1][dicevalue]=tile. handler[1][dicevalue];
                tile. handler[0][dicevalue]=7;
                tile. handler[1][dicevalue]=7;
                if(highhead2<player2[0][dicevalue]){
                    highhead2=player2[0][dicevalue];
                    hightail2=player2[1][dicevalue];
                }
                check=false;
            }
        }
      }
            System.out.println(character[1]+"'s tiles");
            for(int x=0;x<49;x++){
                    if(player2[0][x]<7&&player2[1][x]<7){
                        System.out.print(player2[0][x]+"\t"+player2[1][x]);
                        System.out.println();
                    }
            }
      if(highhead1>highhead2){
          JOptionPane.showMessageDialog(null,character[0]+" Mangga Tipayun");
          game();
      }
      else if(highhead1<highhead2){
          JOptionPane.showMessageDialog(null,character[1]+" Sok Duluan Mainkan");
          character[2]=character[0];
          character[0]=character[1];
          character[1]=character[2];
          for(int x=0;x<49;x++){
              temp=player1[0][x];
              player1[0][x]=player2[0][x];
              player2[0][x]=temp;
              temp=player1[1][x];
              player1[1][x]=player2[1][x];
              player2[1][x]=temp;
          }
          game();
      }
      else{
          if(hightail1>hightail2){
              JOptionPane.showMessageDialog(null,character[0]+" Mangga Tipayun");
              game();
          }
          else{
              JOptionPane.showMessageDialog(null,character[1]+" Sok Duluan Mainkan");
                character[2]=character[0];
                character[0]=character[1];
                character[1]=character[2];
                for(int x=0;x<49;x++){
                    temp=player1[0][x];
                    player1[0][x]=player2[0][x];
                    player2[0][x]=temp;
                    temp=player1[1][x];
                    player1[1][x]=player2[1][x];
                    player2[1][x]=temp;
                }
              game();
          }
      }
            
      
    }
    public static void newCharacter(){
        if (charcount<2){
            character[charcount]=JOptionPane.showInputDialog("Isi Nama:");
            charcount+=1;
        }
    }
    public static void printgamecycle(){
        System.out.println("Aksi Permainan");
        for(int x=0;x<98;x++){
                if(interval[0][x]<7&&interval[0][x]<7)
                System.out.println(interval[0][x]+"\t"+interval[1][x]);
        }
    }
    
    public static void game(){
        check=true;
        while(check){
            while(check){
                try{
                highhead1=Integer.parseInt(JOptionPane.showInputDialog(character[0]+"'s turn\nEnter Masukan angka kartu domino anda Mas :"));
                hightail1=Integer.parseInt(JOptionPane.showInputDialog(character[0]+"'s turn\nEnter Masukan angka kartu domino anda Mas:"));
                check=false;
                }
                catch(NumberFormatException e){
                JOptionPane.showMessageDialog(null,"ga ada Di kartu punya Mu Mas","ERROR",JOptionPane.ERROR_MESSAGE);
                }
            }
            
            if(highhead1<=6&&highhead1>=0&&hightail1<=6&&hightail1>=0){
                   for(int x=0;x<49;x++){
                      if(player1[0][x]==highhead1&&player1[1][x]==hightail1){
                         interval[0][x2]=player1[0][x];
                         interval[1][y2]=player1[1][x];
                         player1[0][x]=7;
                         player1[1][x]=7;
                      }
                  }
                check=false;
            printgamecycle();
            }
            
      }
        
        
while(checkgame){
    counter1=0;
    for(int x=0;x<49;x++){
        if(tile. handler[0][x]==7&&tile. handler[1][x]==7)
            counter1+=1;
    }
    if(counter1==49){
        for(int x=0;x<49;x++){
            if(player1[0][x]<7&&player1[1][x]<7)
                counterplayer1+=1;
            if(player2[0][x]<7&&player2[1][x]<7)
                counterplayer2+=1;
        }
        if(counterplayer1<counterplayer2){
            JOptionPane.showMessageDialog(null,character[0]+"Wins");
            checkgame=false;
            check=false;
            checkroll=false;
            checkroll1=false;
        }
        else if(counterplayer1>counterplayer2){
            JOptionPane.showMessageDialog(null,character[1]+"Wins");
            checkgame=false;
            check=false;
            checkroll=false;
            checkroll1=false;
        }
        else if(counterplayer1==counterplayer2){
            JOptionPane.showMessageDialog(null,"DRAW!!!");
            checkgame=false;
            check=false;
            checkroll=false;
            checkroll1=false;
        }
    }
        while(true){
            check=false;
            checkroll1=true;
            while(checkroll1){
                checkroll=true;
                for(int x=0;x<49;x++){
                    if(highhead1==player2[0][x]||highhead1==player2[1][x]||hightail1==player2[0][x]||hightail1==player2[1][x]){
                        check=true;
                        checkroll=false;
                        checkroll1=false;
                    }
                    else if(counter1==49){
                        check=false;
                        checkroll=false;
                        checkroll1=false;
                    }
                    
                } 
                while(checkroll){
                    dicevalue=dice.roll();
                        if(tile. handler[0][dicevalue]<7 && tile. handler[1][dicevalue]<7){
                            JOptionPane.showMessageDialog(null,character[1]+" chose to pass, required to get new domino from boneyard");
                            player2[0][dicevalue]=tile. handler[0][dicevalue];
                            player2[1][dicevalue]=tile. handler[1][dicevalue];
                            tile. handler[0][dicevalue]=7;
                            tile. handler[1][dicevalue]=7;
                            highhead2=highhead1;
                            hightail2=hightail1;
                            check=false;
                            checkroll=false;
                            checkroll1=false;
                        }
                        counter1=0;
                        for(int x=0;x<49;x++){
                        if(tile. handler[0][x]==7&&tile. handler[1][x]==7)
                        counter1+=1;
                        }
                        if(counter1==49){
                            check=false;
                            checkroll=false;
                            checkroll1=false;
                        }
                 }    
            }
            System.out.println(character[1]+"'s tiles");
            for(int x=0;x<49;x++){
                if(player2[0][x]<7&&player2[1][x]<7)
                System.out.println("("+player2[0][x]+","+player2[1][x]+")");
            }
            while(check){
                while(check){
                try{
                highhead2=Integer.parseInt(JOptionPane.showInputDialog(character[1]+"'s turn\nEnter a head tile number to use:"));
                hightail2=Integer.parseInt(JOptionPane.showInputDialog(character[1]+"'s turn\nEnter a tail tile number to use:"));
                    while(check){
                    toplace=Integer.parseInt(JOptionPane.showInputDialog("Where to place the tiles:\n[0]head portion\n[1]tail portion"));
                    if(toplace==0||toplace==1){
                        check=false;
                    }
                    else
                    JOptionPane.showMessageDialog(null,"WRONG INPUT","Warning",JOptionPane.WARNING_MESSAGE);
                    }
                check=false;
                }
                catch(NumberFormatException e){
                JOptionPane.showMessageDialog(null,"WRONG INPUT","ERROR",JOptionPane.ERROR_MESSAGE);
                }
                }
                check=true;
            if(toplace==0){ 
                if(highhead2==highhead1){
                   for(int x=0;x<49;x++){
                      if(player2[0][x]==highhead2&&player2[1][x]==hightail2){
                         x2-=1;
                         y2-=1;
                         interval[0][x2]=player2[1][x];
                         interval[1][y2]=player2[0][x];
                         highhead2=player2[1][x];
                         hightail2=hightail1;
                         player2[0][x]=7;
                         player2[1][x]=7;
                         check=false;
                         
                      }
                  }
                }
                else if(hightail2==highhead1){
                     for(int x=0;x<49;x++){
                      if(player2[0][x]==highhead2&&player2[1][x]==hightail2){
                         x2-=1;
                         y2-=1;
                         interval[0][x2]=player2[0][x];
                         interval[1][y2]=player2[1][x];
                         hightail2=hightail1;
                         player2[0][x]=7;
                         player2[1][x]=7;
                         check=false;
                      }
                  }
                }
            }
            
            else if(toplace==1){
                if(highhead2==hightail1){
                   for(int x=0;x<49;x++){
                      if(player2[0][x]==highhead2&&player2[1][x]==hightail2){
                         xx2+=1;
                         yy2+=1;
                         interval[0][xx2]=player2[0][x];
                         interval[1][yy2]=player2[1][x];
                         highhead2=highhead1;
                         player2[0][x]=7;
                         player2[1][x]=7;
                         check=false;
                      }
                  }
                }
                else if(hightail2==hightail1){
                    for(int x=0;x<49;x++){
                      if(player2[0][x]==highhead2&&player2[1][x]==hightail2){
                         xx2+=1;
                         yy2+=1;
                         interval[0][xx2]=player2[1][x];
                        interval[1][yy2]=player2[0][x];
                         highhead2=highhead1;
                         hightail2=player2[0][x];
                         player2[0][x]=7;
                         player2[1][x]=7;
                         check=false;
                      }
                  }
                }
            }
            }
            printgamecycle();
                counterplayer2=0;
                for(int x=0;x<49;x++){
                if(player2[0][x]<7&&player2[1][x]<7)
                counterplayer2+=1;
                }
                if(counterplayer2==0){
                JOptionPane.showMessageDialog(null,character[1]+" Wins!!!");
                checkgame=false;
                check=false;
                checkroll=false;
                checkroll1=false;
                }
                else{
                check=false;
                checkroll1=true;
                }
        break;
    }
                
         
        while(true){ 
            while(checkroll1){
                checkroll=true;
                for(int x=0;x<49;x++){
                    if(highhead2==player1[0][x]||highhead2==player1[1][x]||hightail2==player1[0][x]||hightail2==player1[1][x]){
                        check=true;
                        checkroll=false;
                        checkroll1=false;
                    }
                    else if(counter1==49){
                        check=false;
                        checkroll=false;
                        checkroll1=false;
                    }
                }
                while(checkroll){
                    dicevalue=dice.roll();
                        if(tile. handler[0][dicevalue]<7 && tile. handler[1][dicevalue]<7){
                            JOptionPane.showMessageDialog(null,character[0]+" chose to pass, required to get new domino from boneyard");
                            player1[0][dicevalue]=tile. handler[0][dicevalue];
                            player1[1][dicevalue]=tile. handler[1][dicevalue];
                            tile. handler[0][dicevalue]=7;
                            tile. handler[1][dicevalue]=7;
                            highhead1=highhead2;
                            hightail1=hightail2;
                            check=false;
                            checkroll=false;
                            checkroll1=false;
                        }
                        counter1=0;
                        for(int x=0;x<49;x++){
                        if(tile. handler[0][x]==7&&tile. handler[1][x]==7)
                        counter1+=1;
                        }
                        if(counter1==49){
                            check=false;
                            checkroll=false;
                            checkroll1=false;
                        }
                }
            }
            System.out.println(character[0]+"'s tiles");
            for(int x=0;x<49;x++){
                if(player1[0][x]<7&&player1[1][x]<7)
                System.out.println(player1[0][x]+"\t"+player1[1][x]);
            }
            while(check){
                while(check){
                try{
                highhead1=Integer.parseInt(JOptionPane.showInputDialog(character[0]+"'s turn\nEnter a your head tile number to use:"));
                hightail1=Integer.parseInt(JOptionPane.showInputDialog(character[0]+"'s turn\nEnter a your tail tile number to use:"));
                while(check){
                    toplace=Integer.parseInt(JOptionPane.showInputDialog("Where to place the tiles:\n[0]head portion\n[1]tail portion"));
                    if(toplace==0||toplace==1){
                    check=false;
                    }
                    else
                    JOptionPane.showMessageDialog(null,"WRONG INPUT","Warning",JOptionPane.WARNING_MESSAGE);
                    }
                check=false;
                }
                catch(NumberFormatException e){
                JOptionPane.showMessageDialog(null,"WRONG INPUT","ERROR",JOptionPane.ERROR_MESSAGE);
                }
                }
                check=true;
            if(toplace==0){ 
                if(highhead1==highhead2){
                   for(int x=0;x<49;x++){
                      if(player1[0][x]==highhead1&&player1[1][x]==hightail1){
                         x2-=1;
                         y2-=1;
                         interval[0][x2]=player1[1][x];
                         interval[1][y2]=player1[0][x];
                         highhead1=player1[1][x];
                         hightail1=hightail2;
                         player1[0][x]=7;
                         player1[1][x]=7;
                         check=false;
                         
                      }
                  }
                }
                else if(hightail1==highhead2){
                     for(int x=0;x<49;x++){
                      if(player1[0][x]==highhead1&&player1[1][x]==hightail1){
                         x2-=1;
                         y2-=1;
                         interval[0][x2]=player1[0][x];
                         interval[1][y2]=player1[1][x];
                         hightail1=hightail2;
                         player1[0][x]=7;
                         player1[1][x]=7;
                         check=false;
                      }
                  }
                }
            }
            
            else if(toplace==1){
                if(highhead1==hightail2){
                   for(int x=0;x<49;x++){
                      if(player1[0][x]==highhead1&&player1[1][x]==hightail1){
                        xx2+=1;
                         yy2+=1;
                         interval[0][xx2]=player1[0][x];
                         interval[1][yy2]=player1[1][x];
                         highhead1=highhead2;
                         player1[0][x]=7;
                         player1[1][x]=7;
                         check=false;
                      }
                  }
                }
                else if(hightail1==hightail2){
                    for(int x=0;x<49;x++){
                      if(player1[0][x]==highhead1&&player1[1][x]==hightail1){
                         xx2+=1;
                         yy2+=1;
                         interval[0][xx2]=player1[1][x];
                         interval[1][yy2]=player1[0][x];
                         highhead1=highhead2;
                         hightail1=player1[0][x];
                         player1[0][x]=7;
                         player1[1][x]=7;
                         check=false;
                      }
                  }
                }
            }
            }
            printgamecycle();
                counterplayer1=0;
                for(int x=0;x<49;x++){
                if(player1[0][x]<7&&player1[1][x]<7)
                counterplayer1+=1;
                }
                if(counterplayer1==0){
                JOptionPane.showMessageDialog(null,character[0]+" LOE MENANG!!!");
                checkgame=false;
                check=false;
                checkroll=false;
                checkroll1=false;
                }
        break;
    }
}
}
}

dan ini adalah screenshot hasil dari coding tsb stelah dieksekusi

»»  READMORE...

Multithreading

Multithreading mengacu kepada dua atau lebih task (tugas, thread) yang berjalan (sedang dieksekusi) di dalam satu program. Thread merupakan suatu path eksekusi independen di dalam program. Banyak thread dapat nerjalan secara konkuren (berbarengan) di dalam program. Setiap thread di dalam Java dibuat dan dikendalikan oleh kelas java.lang.Thread. Suatu program Java dapat mempunyai banyak thread, dan thread-thread ini dapat berjalan secara bersamaan, secara asinkron atau sinkron.

Multithreading mempunyai beberapa keuntungan, dibandingkan multiprocessing, di antaranya:
  • Thread bersifat lightweight, sedangkan proses lebih berat. Perlu diketahui bahwa proses adalah program yang sedang berada di memory atau processor, sedang dieksekusi. Thread dapat diartikan sebagai anak dari proses.
  • Thread-thread berbagi pakai ruang alamat yang sama dan karena itu dapat berbagi pakai data dan kode (instruksi)
  • Context switching antar thread biasanya lebih murah daripada antar proses.
  • Biaya komunikasi antar thread relatif lebih rendah daripada komunikasi antar proses.
  • Thread memungkinkan task-task berbeda dikerjakan secara konkuren.
Kelas Thread merupakan turunan dari kelas Object. Kelas Object sendiri mempunyai metode notify(), notifyAll() dan wait(), sedangkan kelas Thread menyediakan metode sleep() dan yield(). Metode-metode ini akan sering digunakan dalam pengelolaan aplikasi banyak thread.

Pembuatan Thread  
Terdapat 2 (dua) cara membuat thread di dalam Java: 
  • Mengimplementasikan interface Runnable (java.lang.Runnable)
  • Menurunkan (extend) kelas Thread (java.lang.Thread)

»»  READMORE...

RPC ( Remote Procedure Call )

RPC adalah sebuah metode yang memungkinkan kita untuk mengakses sebuah prosedur yang berada di komputer lain. Untuk dapat melakukan ini sebuah server harus menyediakan layanan remote procedure. Pendekatan yang dilakukan adalah sebuah server membuka socket, lalu menunggu client yang meminta prosedur yang disediakan server. RPC masih menggunakan cara primtif dalam pemrograman yaitu menggunakan paradigma procedural programming.

RPC digunakan untuk administrasi sistem sehingga seorang administrator jaringan dapat mengakses sistemnya dan mengelola sistemnya darimna saja, selama sistemnya terhubung ke jaringan.

Cara Kerja RPC
Tiap prosedur yang dipanggil dalam RPC, maka proses ini harus berkoneksi dengan server remote dengan mengirimkan semua parameter yang dibutuhkan, menunggu balasan dari server dan melakukan proses kemudian selesai. Proses di atas disebut juga dengan stub pada sisi klien. Sedangkan Stub pada sisi server adalah proses menunggu tiap message yang berisi permintaan mengenai prosedur tertentu. 

Langkah-langkah dalam RPC

  1. Prosedur client memanggil client stub
  2. Client stub membuat pesan dan memanggil OS client
  3. OS client mengirim pesan ke OS server
  4. OS server memberikan pesan ke server stub
  5. Server stub meng-unpack parameter-parameter untuk memanggil server
  6. Server mengerjakan operasi, dan mengembalikan hasilnya ke server stub
  7. Server stub meng-pack hasil tersebut dan memanggil OS server
  8. OS server mengirim pesan (hasil) ke OS client
  9. OS client memberikan pesan tersebut ke client stub
  10. Client stub meng-unpack hasil dan mengembalikan hasil tersebut ke client
  
»»  READMORE...

Sunday, June 9, 2013

contoh socket connection

Salah satu cara untuk komunikasi client server menggunakan socket connection.
berikut adalah salah satu contoh codingnya:

Coding pada PC Server
*********************
package tugas_server;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.logging.Level;
import java.util.logging.Logger;

public class Tugas_server {

    public static void main(String[] args) {
        try {
            ServerSocket ss = new ServerSocket(5111);
            Socket s;
            String balasan;
            String balasan2;
            ObjectInputStream in = null;
            ObjectOutputStream out = null;
            s = ss.accept();
            out = new ObjectOutputStream(s.getOutputStream());
            out.flush();
            in = new ObjectInputStream(s.getInputStream());
            balasan = "";
            balasan2 = "";
            while (true) {
                balasan = "";
                balasan2 = "";
                balasan = ReadMessage(in);
                if (balasan.equals("exit")) break;
                else {
                    if(balasan.equals("ini client"))
                    {
                    SendMessage("ini server, masukan username", out);
                    balasan2 = ReadMessage(in);
                    if (balasan2.equals("admin")){ SendMessage("Selamat Datang Admin", out);}
                    else {
                        if (balasan2.equals("user")){SendMessage("Selamat Datang User", out);}
                        else SendMessage("username tidak diketahui", out);
                        }
                    }
                    else
                    {
                        SendMessage("perintah tidak diketahui", out);
                }
            }
            }
    in.close();
    out.close();
    s.close();
    ss.close();
}catch (IOException ex){
    Logger.getLogger(Tugas_server.class.getName()).log(Level.SEVERE,null,ex);
    }
    }
 public static String ReadMessage(ObjectInputStream in)
 {
 String Reader="";
 try {
     Reader=(String)in.readObject();
 }catch (IOException ex){
     Logger.getLogger(Tugas_server.class.getName()).log(Level.SEVERE,null,ex);
 }catch (ClassNotFoundException ex){
     Logger.getLogger(Tugas_server.class.getName()).log(Level.SEVERE,null,ex);
 }
 System.out.println(Reader);
 return Reader;
 }
 public static void SendMessage(String word, ObjectOutputStream out)
 {
     try{
         out.writeObject(word);
         out.flush();
     }catch (IOException ex){
         Logger.getLogger(Tugas_server.class.getName()).log(Level.SEVERE,null,ex);
     }
    }

}


***********************************************************************

Coding pada PC Client.
********************

package tgs_client;
import java.util.Scanner;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author UNLA
 */
public class Tgs_Client {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws IOException{
        Socket s=new Socket("10.0.0.4", 5111);
        ObjectInputStream in=null;
        ObjectOutputStream out=null;
        Scanner scanf=new Scanner(System.in);
        String input="";
        String balasan;
        String balasan2;
        out=new ObjectOutputStream(s.getOutputStream());
        out.flush();
        in=new ObjectInputStream(s.getInputStream());
        balasan = "";
        balasan2="";
        while(true)
        {
            balasan="";
            balasan2="";
            input=scanf.nextLine();
            SendMessage(input, out);
            if(input.equals("exit"))break;
            else
            {
                balasan=ReadMessage(in);
                if(balasan.equals("ini server, masukkan username"))
                {
                    input=scanf.nextLine();
                    SendMessage(input, out);
                    balasan2=ReadMessage(in);

                }
            }
        }
        in.close();
        out.close();
        s.close();

        // TODO code application logic here
    }
public static void SendMessage(String word, ObjectOutputStream out)
{
    try{
        out.writeObject(word);
        out.flush();
    } catch (IOException ex){
        Logger.getLogger(Tgs_Client.class.getName()).log(Level.SEVERE, null, ex);
    }
}
public static String ReadMessage(ObjectInputStream in)
{
    String reader="";
    try{
        reader=(String) in.readObject();
    } catch (IOException ex){
        Logger.getLogger(Tgs_Client.class.getName()).log(Level.SEVERE, null, ex);
    } catch (ClassNotFoundException ex){
        Logger.getLogger(Tgs_Client.class.getName()).log(Level.SEVERE, null, ex);
    }
    System.out.println(reader);
    return reader;
}
}


Dalam coding client ganti coding localhost dengan ip komputer Server.
contoh coding client "  Socket s=new Socket("10.0.0.4", 5111);"  dengan mengubah jadi "  Socket s=new Socket("192.168.0.1", 5111);" tergantung ip yang kita setting di komputer sever.

berikut adalah screenshoot ketika program di run:
pada client:


pada server:




»»  READMORE...