//***** import java.net.Socket; import java.net.ServerSocket; import java.util.Map; import java.util.HashMap; import java.util.Random; import java.io.ObjectOutputStream; public class SerialS { public static void main(String[ ] args) throws Exception { ServerSocket ssock = new ServerSocket(9876); Map map = new HashMap(); Random r = new Random(); // Serialize a Map of random integers to clients. while (true) { map.clear(); // remove any elements Socket sock = ssock.accept(); int how_many = Math.abs(r.nextInt()) % 5; // Populate a map with how_many ints: // key is in decimal, value in hexadecimal for (int i = 0; i < how_many; i++) { int n = r.nextInt(); map.put(new Integer(n), Integer.toHexString(n)); } ObjectOutputStream out = new ObjectOutputStream(sock.getOutputStream()); out.writeObject(map); out.flush(); out.close(); } } }