Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (4)
- import java.io.Serializable;
- public class Bank implements Serializable {
- String name;
- String id;
- double balance;
- public Bank(String name, String id, double balance) {
- this.name = name;
- this.id = id;
- this.balance = balance;
- }
- public String getName() { return name; }
- public void setName(String name) {
- this.name = name;
- }
- public String getId() {return id;}
- public void setId(String id) {
- this.id = id;
- }
- public double getBalance() { return balance;}
- public void setBalance(double balance) {
- this.balance = balance;
- }
- public void display() {
- System.out.println("Name : " + name);
- System.out.println("ID : " + id);
- System.out.println("Balance :" + balance);
- }
- }
- //Server
- import java.net.*;
- import java.io.Serializable;
- public class ServerMain {
- public static void main(String[] args) {
- try {
- ServerSocket ss = new ServerSocket(2020);
- Socket s = ss.accept();
- InputStream is = s.getInputStream();
- ObjectInputStream objInS = new ObjectInputStream(is);
- System.out.println("Server running...");
- System.out.println("Waiting for inputs...\n\n");
- Bank b = (Bank) objInS.readObject();
- b.display();
- if (!b.equals(null)) {
- System.out.println(b.toString());
- }
- else {
- System.out.println("No object received.");
- }
- System.out.println("\n\nClient exited.");
- objInS.close();
- s.close();
- ss.close();
- } catch (IOException e) {
- e.printStackTrace();
- } catch (ClassNotFoundException e) {
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement