01: //*****
02: import java.net.Socket;
03: import java.net.ServerSocket;
04: import java.util.Map;
05: import java.util.HashMap;
06: import java.util.Random;
07: import java.io.ObjectOutputStream;
08: public class SerialS {
09:     public static void main(String[ ] args) throws Exception {
10:         ServerSocket ssock = new ServerSocket(9876);
11:         Map map = new HashMap();
12:         Random r = new Random();
13:         // Serialize a Map of random integers to clients.
14:         while (true) {
15:            map.clear();   // remove any elements
16:            Socket sock = ssock.accept();
17:            int how_many = Math.abs(r.nextInt()) % 5;
18:            // Populate a map with how_many ints: 
19:            //  key is in decimal, value in hexadecimal
20:            for (int i = 0; i < how_many; i++) {
21:                int n = r.nextInt();
22:                map.put(new Integer(n), Integer.toHexString(n));
23:            }
24:            ObjectOutputStream out = 
25:                new ObjectOutputStream(sock.getOutputStream());
26:            out.writeObject(map);
27:            out.flush();
28:            out.close();
29:         }
30:     }
31: }