Advertisement
NB52053

Assignment_LAB_8

Aug 12th, 2017
453
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.93 KB | None | 0 0
  1. (4)
  2. import java.io.Serializable;
  3.  public class Bank implements Serializable {
  4.     String name;
  5.     String id;
  6.     double balance;
  7.      
  8.     public Bank(String name, String id, double balance) {
  9.         this.name = name;
  10.         this.id = id;
  11.         this.balance = balance;
  12.     }
  13.  
  14.     public String getName() { return name; }
  15.  
  16.     public void setName(String name) {
  17.         this.name = name;
  18. }
  19.  
  20.     public String getId() {return id;}
  21.  
  22.     public void setId(String id) {
  23.         this.id = id;
  24.     }
  25.  
  26.     public double getBalance() { return balance;}
  27.  
  28.     public void setBalance(double balance) {
  29.         this.balance = balance;
  30.     }
  31.      
  32.     public void display() {
  33.         System.out.println("Name : " + name);
  34.         System.out.println("ID : " + id);
  35.         System.out.println("Balance :" + balance);
  36.     }
  37. }
  38.  
  39. //Server
  40.  import java.net.*;
  41.  import java.io.Serializable;
  42. public class ServerMain {
  43.  
  44.     public static void main(String[] args) {
  45.         try {
  46.             ServerSocket ss = new ServerSocket(2020);
  47.             Socket s = ss.accept();
  48.              
  49.             InputStream is = s.getInputStream();
  50.             ObjectInputStream objInS = new ObjectInputStream(is);
  51.              
  52.             System.out.println("Server running...");
  53.             System.out.println("Waiting for inputs...\n\n");
  54.              
  55.             Bank b = (Bank) objInS.readObject();
  56.             b.display();
  57.  
  58.             if (!b.equals(null)) {
  59.                 System.out.println(b.toString());
  60.             }
  61.             else {
  62.                 System.out.println("No object received.");
  63.             }
  64.              
  65.             System.out.println("\n\nClient exited.");
  66.             objInS.close();
  67.             s.close();
  68.             ss.close();
  69.         } catch (IOException e) {
  70.             e.printStackTrace();
  71.         } catch (ClassNotFoundException e) {
  72.             e.printStackTrace();
  73.         }
  74.     }
  75.  
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement