01: /*
02: * @(#)SerializationTestServer.java 1.9 06/10/10
03: *
04: * Copyright 1990-2006 Sun Microsystems, Inc. All Rights Reserved.
05: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
06: *
07: * This program is free software; you can redistribute it and/or
08: * modify it under the terms of the GNU General Public License version
09: * 2 only, as published by the Free Software Foundation.
10: *
11: * This program is distributed in the hope that it will be useful, but
12: * WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * General Public License version 2 for more details (a copy is
15: * included at /legal/license.txt).
16: *
17: * You should have received a copy of the GNU General Public License
18: * version 2 along with this work; if not, write to the Free Software
19: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20: * 02110-1301 USA
21: *
22: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
23: * Clara, CA 95054 or visit www.sun.com if you need additional
24: * information or have any questions.
25: *
26: */
27: package foundation;
28:
29: import java.net.Socket;
30: import java.net.ServerSocket;
31: import java.io.InputStream;
32: import java.io.ObjectInputStream;
33: import foundation.SerializationTestObject;
34:
35: /** Receives connection from a SerializationTestClient and receives
36: and prints two objects (a String array and a custom object). */
37:
38: public class SerializationTestServer {
39: public static void main(String[] args) {
40: try {
41: System.out.println("Waiting for connection from "
42: + "SerializationTestClient...");
43: ServerSocket serv = new ServerSocket(13913);
44: Socket sock = serv.accept();
45: InputStream inStr = sock.getInputStream();
46: ObjectInputStream objInStr = new ObjectInputStream(inStr);
47: String[] strs = (String[]) objInStr.readObject();
48: System.out.println("Received " + strs.length + " strings:");
49: for (int i = 0; i < strs.length; i++) {
50: System.out.println("String " + i + ": " + strs[i]);
51: }
52: SerializationTestObject obj = (SerializationTestObject) objInStr
53: .readObject();
54: System.out.println("Received SerializationTestObject:\n"
55: + obj);
56: System.out.println("Closing sockets...");
57: sock.close();
58: serv.close();
59: System.out
60: .println("SerializationTestServer exiting successfully.");
61: } catch (Exception e) {
62: e.printStackTrace();
63: System.out
64: .println("ERROR: SerializationTestServer exiting unsuccessfully.");
65: }
66: }
67: }
|