Метод
readObject, в строке 32 , в случае, если клиент после установки соединения не записал в поток никаких данных, приведет:
1 package com.asw.net.ex2;2 import java.io.*;3 import java.net.*;4 5 public class BillingClientService extends Thread {6 ObjectInputStream ois;7 ObjectOutputStream oos;8 BillingService bs;9 Socket s;10 11 public BillingClientService(BillingService bs,Socket s){12 System.out.println("Constructor BillingClientService\n");13 this.bs = bs;14 this.s = s;15 try {16 this.oos = new ObjectOutputStream(s.getOutputStream());17 this.ois = new ObjectInputStream(s.getInputStream());18 } catch (IOException e) {19 // TODO Auto-generated catch block20 e.printStackTrace();21 }22 23 System.out.println("Stream`s done \n socket="+s);24 }25 public void run(){26 System.out.println("ClientService thread started\n");27 boolean work = true;28 while (work) {29 int command;30 Object o;31 try {32 o = ois.readObject(); 33 if (o instanceof Card[]) {34 Card[] cards = (Card[])o;35 for (int i=0;i<cards.length;i++){36 bs.addNewCard(cards[i]);37 }38 }else if (o instanceof CardOperation[]){39 CardOperation[] co = (CardOperation[])o;40 for (int i=0;i<co.length;i++){41 bs.addMoney(co[i].card,co[i].amount);42 }43 }else if (o instanceof String){44 oos.writeObject(bs.getCard((String)o)); 45 }else System.out.println("Bad operation");46 47 } catch (IOException e) {48 e.printStackTrace();49 } catch (ClassNotFoundException e) {50 e.printStackTrace();51 }52 }53 }54 }