01: // MuxClientFactory.java
02: // $Id: MuxClientFactory.java,v 1.4 2000/08/16 21:37:42 ylafon Exp $
03: // (c) COPYRIGHT MIT and INRIA, 1996.
04: // Please first read the full copyright statement in file COPYRIGHT.html
05:
06: package org.w3c.jigsaw.http.mux;
07:
08: import java.io.IOException;
09: import java.io.PrintStream;
10:
11: import java.net.ServerSocket;
12: import java.net.Socket;
13:
14: import org.w3c.www.mux.MuxProtocolHandler;
15: import org.w3c.www.mux.MuxStream;
16: import org.w3c.www.mux.SampleMuxHandler;
17:
18: import org.w3c.jigsaw.http.ClientFactory;
19: import org.w3c.jigsaw.http.httpd;
20:
21: public class MuxClientFactory implements ClientFactory {
22: public static final int HTTP_PORT = 80;
23:
24: httpd server = null;
25: int cid = -1;
26: SampleMuxHandler handler = null;
27: MuxProtocolHandler httphandler = null;
28:
29: public void shutdown(boolean force) {
30: System.out.println("Shutdown: not implemented.");
31: }
32:
33: /**
34: * Handle that new incomming connection.
35: * Wrap the given socket into a MuxStream, the rest is handled magically.
36: * @param socket The newly accepted socket.
37: */
38:
39: public void handleConnection(Socket socket) {
40: try {
41: new MuxStream(true, handler, socket);
42: } catch (IOException ex) {
43: server
44: .errlog(getClass().getName()
45: + ": rejected newly accepted connection (IOerror): "
46: + ex.getMessage());
47: }
48: }
49:
50: /**
51: * Create a suitable server socket for our server context.
52: * @return A ServerSocket instance.
53: * @exception IOException If some IO error occured while creating the
54: * server socket.
55: */
56:
57: public ServerSocket createServerSocket() throws IOException {
58: return new ServerSocket(server.getPort(), 128);
59: }
60:
61: /**
62: * Initialize the MUX client factory.
63: * @param server The server context in which this factory is to run.
64: */
65:
66: public void initialize(httpd server) {
67: // Initialize the server itself:
68: this .server = server;
69: // Configure the mux stream handler:
70: handler = (SampleMuxHandler) SampleMuxHandler
71: .getStreamHandler();
72: httphandler = new MuxHttpHandler(server);
73: handler.registerHandler(HTTP_PORT, httphandler);
74: }
75:
76: public MuxClientFactory() {
77: super();
78: }
79:
80: }
|