51ddf9056cb8775cd57a08a24b1e0a72d29dba38
[spider.git] / spider-web / spiderclient.java
1 import java.awt.*;
2 import java.applet.*;
3 import java.io.*;
4 import java.net.*;
5
6
7 public class spiderclient extends Applet {
8
9         public void init() {
10                 String p;
11         
12                 cf = new spiderframe(this);
13                 cf.resize(800,600);
14                 
15                 p = getParameter("CALL");
16                 if (p != null) cf.setCall(p);
17                 
18                 p = getParameter("FULLNAME");
19                 if (p != null) cf.setFullname(p);
20
21                 p = getParameter("HOSTNAME");
22                 if (p != null) cf.setHostname(p);               
23
24                 p = getParameter("PORT");
25                 if (p != null) cf.setPort(p);
26
27                 p = getParameter("CHANNEL");
28                 if (p != null) cf.setChannel(p);
29
30                 Beep = getAudioClip(getCodeBase(), "ding.au");
31                 // cf.login();
32                 cf.resize(655, 380);
33                 
34                 cf.show();
35         }
36         
37         public void doconnect() {
38                 try {
39                         s = new Socket(cf.getHostname(), Integer.parseInt(cf.getPort()));
40                         out = new PrintStream(s.getOutputStream());
41                         in = new DataInputStream(s.getInputStream());
42                         cf.initPrintStream(out);
43                 
44                         listener = new StreamListener(cf, in);
45                         
46                         out.println(cf.getCall());
47                         out.println(cf.getFullname());
48                 }
49                 catch (IOException e) { 
50                         InfoDialog id = new InfoDialog(cf, "Error", e.toString());
51                 }
52                 cf.connected();
53                 Beep.play();
54         }
55
56         public void dodisconnect() {
57                 try {
58                         s.close();
59                 }
60                 catch (IOException e) { 
61                         InfoDialog id = new InfoDialog(cf, "Error", e.toString());
62                 }
63                 cf.disconnected();
64                 Beep.play();
65         }
66
67         void beep() {
68                 Beep.play();
69         }
70
71         private Socket s = null;
72         private PrintStream out;
73         private DataInputStream in;
74         private StreamListener listener;
75         
76         private AudioClip Beep; 
77
78         spiderframe cf;
79 }
80
81 class StreamListener extends Thread {
82         DataInputStream in;
83         spiderframe cf;
84         
85         public StreamListener(spiderframe cf, DataInputStream in) {
86                 this.in = in;
87                 this.cf = cf;
88                 this.start();
89         }
90         
91         public void run() {
92                 String line;
93                                 
94                 try {
95                         for (;;) {
96                         line = in.readLine();   
97                         
98                         // schrieb nur jede 2te zeile , deswegen //
99                         // line = in.readLine();
100                         
101                         
102                         
103                         
104                         
105                         if (line == null) break;
106                                 cf.setText(line);
107                         }
108                         cf.disconnected();
109                 }
110                 catch (IOException e) {
111                         cf.setText(e.toString());
112                         cf.disconnected();
113                 }
114                 
115                 finally { cf.setText("Connection closed by server."); }
116         }
117 }