]> scm.dxcluster.org Git - spider.git/blob - spider-web/spiderclient.java
add CTY-2614
[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("PASSWORD");
19                 if (p != null) cf.setPassword(p);
20         
21                 p = getParameter("FULLNAME");
22                 if (p != null) cf.setFullname(p);
23
24                 p = getParameter("HOSTNAME");
25                 if (p != null) cf.setHostname(p);               
26
27                 p = getParameter("PORT");
28                 if (p != null) cf.setPort(p);
29
30                 p = getParameter("CHANNEL");
31                 if (p != null) cf.setChannel(p);
32
33                 p = getParameter("NODECALL");
34                 if (p != null) cf.setNodecall(p);
35                 
36                 Beep = getAudioClip(getCodeBase(), "ding.au");
37                 // cf.login();
38                 cf.resize(655, 380);
39                 
40                 cf.show();
41         }
42         
43         public void doconnect() {
44                 try {
45                         s = new Socket(cf.getHostname(), Integer.parseInt(cf.getPort()));
46                         out = new PrintStream(s.getOutputStream());
47                         in = new DataInputStream(s.getInputStream());
48                         cf.initPrintStream(out);
49                 
50                         listener = new StreamListener(cf, in);
51                         
52                         out.println(cf.getCall());
53
54                         if(cf.getPassword().length() > 0) {
55                         out.println(cf.getPassword());
56                         }
57                         // out.println(cf.getFullname());
58                 }
59                 catch (IOException e) { 
60                         InfoDialog id = new InfoDialog(cf, "Error", e.toString());
61                 }
62                 cf.connected();
63                 Beep.play();
64         }
65
66         public void dodisconnect() {
67                 try {
68                         s.close();
69                 }
70                 catch (IOException e) { 
71                         InfoDialog id = new InfoDialog(cf, "Error", e.toString());
72                 }
73                 cf.disconnected();
74                 Beep.play();
75         }
76
77         void beep() {
78                 Beep.play();
79         }
80
81         private Socket s = null;
82         private PrintStream out;
83         private DataInputStream in;
84         private StreamListener listener;
85         
86         private AudioClip Beep; 
87
88         spiderframe cf;
89 }
90
91 class StreamListener extends Thread {
92         DataInputStream in;
93         spiderframe cf;
94         
95         public StreamListener(spiderframe cf, DataInputStream in) {
96                 this.in = in;
97                 this.cf = cf;
98                 this.start();
99         }
100         
101         public void run() {
102                 String line;
103                                 
104                 try {
105                         for (;;) {
106                         line = in.readLine();   
107                         
108                         // schrieb nur jede 2te zeile , deswegen //
109                         // line = in.readLine();
110                         
111                         if (line == null) break;
112                                 cf.setText(line);
113                         }
114                         cf.disconnected();
115                 }
116                 catch (IOException e) {
117                         cf.setText(e.toString());
118                         cf.disconnected();
119                 }
120                 finally { cf.setText("Connection closed by server."); }
121         }
122 }