import java.net.Socket; import java.io.IOException; import java.io.ObjectInputStream; import java.util.Map; import java.util.HashMap; public class SerialC { public static void main (String args[]) { if (args.length < 1) { System.err.println("Usage: SerialC "); return; } try { int how_many = 4; for (int i = 0; i < how_many; i++) { Socket sock = new Socket(args[0], port); ObjectInputStream in = new ObjectInputStream (sock.getInputStream()); Map temp = (Map) in.readObject(); // blocks Map map = new HashMap(); //cast to correct type for (Map.Entry e : temp.entrySet()) map.put((Integer)e.getKey(), (String)e.getValue()); System.out.println ("Received in iteration " + i + ": "); System.out.println (map); sock.close(); } } catch (IOException e) { System.err.println (e); } catch (ClassNotFoundException e) { System.err.println (e); } } private static final int port = 9876; }