OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libjava/] [classpath/] [examples/] [gnu/] [classpath/] [examples/] [CORBA/] [swing/] [x5/] [X5Server.java] - Blame information for rev 781

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 781 jeremybenn
/* GameManagerAddressServer.java --
2
 Copyright (C) 2005 Free Software Foundation, Inc.
3
 
4
 This file is part of GNU Classpath.
5
 
6
 GNU Classpath is free software; you can redistribute it and/or modify
7
 it under the terms of the GNU General Public License as published by
8
 the Free Software Foundation; either version 2, or (at your option)
9
 any later version.
10
 
11
 GNU Classpath 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 for more details.
15
 
16
 You should have received a copy of the GNU General Public License
17
 along with GNU Classpath; see the file COPYING.  If not, write to the
18
 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19
 02110-1301 USA.
20
 
21
 Linking this library statically or dynamically with other modules is
22
 making a combined work based on this library.  Thus, the terms and
23
 conditions of the GNU General Public License cover the whole
24
 combination.
25
 
26
 As a special exception, the copyright holders of this library give you
27
 permission to link this library with independent modules to produce an
28
 executable, regardless of the license terms of these independent
29
 modules, and to copy and distribute the resulting executable under
30
 terms of your choice, provided that you also meet, for each linked
31
 independent module, the terms and conditions of the license of that
32
 module.  An independent module is a module which is not derived from
33
 or based on this library.  If you modify this library, you may extend
34
 this exception to your version of the library, but you are not
35
 obligated to do so.  If you do not wish to do so, delete this
36
 exception statement from your version. */
37
 
38
 
39
package gnu.classpath.examples.CORBA.swing.x5;
40
 
41
import java.io.BufferedWriter;
42
import java.io.File;
43
import java.io.FileWriter;
44
import java.io.IOException;
45
import java.io.OutputStream;
46
import java.net.InetAddress;
47
import java.net.ServerSocket;
48
import java.net.Socket;
49
 
50
/**
51
 * The main executable class of the game manager server.
52
 *
53
 * The manager address server returns the IOR address string of the game
54
 * manager. Hence the user does not need to enter the rather long IOR address
55
 * string and only needs to specify the host and port of the machine where the
56
 * game manager is running.
57
 *
58
 * The manager address server starts the main game manager as well.
59
 *
60
 * This server acts as a HTTP server that always returns the same response. This
61
 * primitive functionality is sufficient for its task.
62
 *
63
 * The more complex CORBA applications should use the name service instead. We
64
 * do not use the name service as this would require to start additional
65
 * external application, specific for the different java platforms.
66
 *
67
 * @author Audrius Meskauskas (AudriusA@Bioinformatics.org)
68
 */
69
public class X5Server
70
{
71
  /**
72
   * Start the game manager.
73
   */
74
  public static void main(String[] args)
75
  {
76
    // Start the game manager, write the IOR to the agreed location.
77
    OrbStarter.startManager(args);
78
 
79
    if (!GameManagerImpl.ok)
80
      {
81
        System.out.println("Unable to start the game manager:");
82
        System.exit(1);
83
      }
84
 
85
    // Print the IOR.
86
    System.out.println(GameManagerImpl.ior);
87
 
88
    String manager_address = null;
89
 
90
    // Start the game manager server.
91
    ServerSocket nameServer = null;
92
    try
93
      {
94
        nameServer = new ServerSocket(OrbStarter.MANAGER_NAMER_PORT);
95
 
96
        System.out.println("The game manager is listening at:");
97
        manager_address = "http://"
98
          + InetAddress.getLocalHost().getHostAddress() + ":"
99
          + nameServer.getLocalPort();
100
 
101
        System.out.println(manager_address);
102
 
103
        System.out.println("Enter this address to the "
104
          + "input field of the game client.");
105
 
106
        System.out.println("Use ^C to stop the manager.");
107
      }
108
    catch (Exception ex)
109
      {
110
        System.out.println("The port " + OrbStarter.MANAGER_NAMER_PORT
111
          + " is not available. The game manager namer will not start.");
112
        System.exit(1);
113
      }
114
 
115
    // Write the IOR to the local file system.
116
    if (OrbStarter.WRITE_URL_TO_FILE != null)
117
      {
118
        try
119
          {
120
            File gmf = new File(OrbStarter.WRITE_URL_TO_FILE);
121
            FileWriter f = new FileWriter(gmf);
122
            BufferedWriter b = new BufferedWriter(f);
123
 
124
            b.write(manager_address);
125
            b.close();
126
          }
127
        catch (IOException e)
128
          {
129
            System.out.println("Local filesystem not accessible."
130
              + "Read IOR from console.");
131
          }
132
      }
133
 
134
    // Do forever.
135
    while (true)
136
      {
137
        try
138
          {
139
            Socket socket = nameServer.accept();
140
 
141
            System.out.println("Connected.");
142
 
143
            // Set the two minutes timeout.
144
            socket.setSoTimeout(1000 * 120);
145
 
146
            OutputStream out = socket.getOutputStream();
147
 
148
            int length = GameManagerImpl.ior.length();
149
 
150
            StringBuilder b = new StringBuilder();
151
            b.append("HTTP/1.0 200 OK\r\n");
152
            b.append("Content-Length: " + length + "\r\n");
153
            b.append("Connection: close\r\n");
154
            b.append("Content-Type: text/plain; charset=UTF-8\r\n");
155
            b.append("\r\n");
156
 
157
            b.append(GameManagerImpl.ior);
158
 
159
            out.write(b.toString().getBytes("UTF-8"));
160
 
161
            socket.shutdownOutput();
162
 
163
            if (!socket.isClosed())
164
              socket.close();
165
 
166
            System.out.println("Completed.");
167
          }
168
        catch (Exception exc)
169
          {
170
            exc.printStackTrace();
171
            System.out.println("Network problem.");
172
          }
173
      }
174
  }
175
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.