01: // Echo.java
02: // $Id: Echo.java,v 1.3 2000/08/16 21:38:02 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.www.mux.handlers;
07:
08: import java.io.IOException;
09: import java.io.InputStream;
10: import java.io.OutputStream;
11:
12: import org.w3c.www.mux.MuxProtocolHandler;
13: import org.w3c.www.mux.MuxSession;
14:
15: /**
16: * The <em>echo</em> protocol handler.
17: */
18:
19: public class Echo extends Thread implements MuxProtocolHandler {
20: InputStream in = null;
21: OutputStream out = null;
22: MuxSession session = null;
23:
24: /**
25: * Run that protocol, can't be easier !
26: */
27:
28: public void run() {
29: byte buffer[] = new byte[1024];
30: int got = -1;
31: try {
32: while ((got = in.read(buffer, 0, buffer.length)) > 0) {
33: out.write(buffer, 0, got);
34: out.flush();
35: }
36: session.shutdown();
37: } catch (Exception ex) {
38: ex.printStackTrace();
39: }
40: }
41:
42: /**
43: * Initialize the <em>echo</em> protocol on that session.
44: * @param session The session to use to speak that protocol.
45: */
46:
47: public void initialize(MuxSession session) throws IOException {
48: this .in = session.getInputStream();
49: this .out = session.getOutputStream();
50: this .session = session;
51: start();
52: }
53:
54: /**
55: * Default public constructor.
56: */
57:
58: public Echo() {
59: super ();
60: setName("echo");
61: }
62:
63: }
|