| Author |
Applet and IIS
|
Roda Aing
Greenhorn
Joined: Jul 13, 2004
Posts: 7
|
|
Hi there! I have an applet calss that works fine with my html page. Now, I want this thing to work with IIS. I coppied the files to my web site home directory on my windows xp pro machine, which IIS 5.1 is installed. It works fine. Then I the files coppied to another machine, windows 2000 server with IIS 5.0 installed. It doesn't work. I go to Internet Explorer and type "http://localhost/myfile.html", then i got the message saying that "Connection refused: connect". I don't know why it doesn't work. Can anyone give me some idea or advise? Thanks, Roda
|
 |
Joe Ess
Bartender
Joined: Oct 29, 2001
Posts: 8291
|
|
|
Is applet or the browser is giving you the error message? If it is the applet, what does the applet do?
|
"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
|
 |
Roda Aing
Greenhorn
Joined: Jul 13, 2004
Posts: 7
|
|
Yes, the applet is giving me an error message saying that "Connection refused: connect". My applet class is to read data from files and build graph. Below is my applet code. import java.io.*; import java.net.*; import java.awt.*; import java.applet.Applet; public class CallsGraph extends Applet{ public void paint(Graphics g){ setBackground(Color.white); String ncalls = ""; int minute = 0; String hour = ""; int count = 100; int inthour; int j = 0; int y1 = 0; int y2 = 0; int y = 0; try{ URL documentBase = getDocumentBase(); String path = documentBase.getPath(); path = path.substring(0, path.lastIndexOf("/")); URL logfileURL1 = new URL(documentBase.getProtocol(), documentBase.getHost(), path + "/Total.log"); URLConnection connection1 = logfileURL1.openConnection(); InputStreamReader isr1 = new InputStreamReader(connection1.getInputStream()); BufferedReader br1 = new BufferedReader(isr1); String lineRead1 = ""; g.setColor(Color.green); while ((lineRead1 = br1.readLine()) != null){ ncalls = lineRead1.substring(7, 10); y = Integer.parseInt(ncalls); g.drawLine(count, 320-y, count, 320); count++; } count = 100; URL logfileURL2 = new URL(documentBase.getProtocol(), documentBase.getHost(), path + "/Record.log"); URLConnection connection2 = logfileURL2.openConnection(); InputStreamReader isr2 = new InputStreamReader(connection2.getInputStream()); BufferedReader br2 = new BufferedReader(isr2); String lineRead2 = ""; while ((lineRead2 = br2.readLine()) != null){ ncalls = lineRead2.substring(7, 10); minute = Integer.parseInt(lineRead2.substring(3, 5)); if (minute == 0) { hour = lineRead2.substring(0, 2); inthour = Integer.parseInt(hour); if (inthour%2 == 0) { hour = Integer.toString(inthour); g.setColor(Color.black); g.drawString(hour, count-3, 340); for (int i = 20; i <= 320; i+=5) { g.drawString(".", count, i); } } } y = Integer.parseInt(ncalls); if (count==100) { y1 = y; } else if (y2 > y1) { if ((y > y1) && (y > y2) ) { y1 = y2; } else if ((y > y1) && (y < y2)) { y1 = y; } } else if (y1 > y2) { if ((y > y2) && (y < y1)) { y1 = y; } else if ((y < y1) && (y < y2)) { y1 = y2; } } g.setColor(Color.red); g.drawLine(count, 320-y, count, 320-y1); y2 = y1; y1 = y; count++; } g.setColor(Color.black); for (int i=20; i<320; i+=20){ ncalls = Integer.toString(i); g.drawString(ncalls,70, 322-i); g.drawString(". . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .", 100, 320-i); } g.drawLine(100, 20, 100, 320); g.drawLine(100, 320, 485, 320); g.drawString(">", 485, 325); g.setColor(Color.green); g.drawString("All Operators",585, 100); g.setColor(Color.red); g.drawString("Mobitel (012)", 585, 130); }catch(MalformedURLException murle){ g.drawString(murle.getMessage(), 100, 100); getAppletContext().showStatus(murle.getMessage()); }catch(IOException ioe){ g.drawString(ioe.getMessage(), 100, 100); getAppletContext().showStatus(ioe.getMessage()); } } } Thanks anyway. Roda
|
 |
Joe Ess
Bartender
Joined: Oct 29, 2001
Posts: 8291
|
|
The only thing I can think of is that this URL: does not match the original. Is IIS running on port 80 (standard HTTP port)?
|
 |
Roda Aing
Greenhorn
Joined: Jul 13, 2004
Posts: 7
|
|
No, my IIS is running on port 8080. I failed to make it run on port 80. The error message is "Address is already in use". If the problem is with the port, how can I make it run on port 8080? Or, how can I make my IIS run on port 80? Thanks, Roda
|
 |
meimei li
Greenhorn
Joined: May 19, 2003
Posts: 24
|
|
|
If your port is at 8080, then your url should be like this "http://localhost:8080/myfile.html". Without the port explicitly specified in URL, it defaults to 80.
|
SCJP
|
 |
Roda Aing
Greenhorn
Joined: Jul 13, 2004
Posts: 7
|
|
Yes, I typed this url, "http://localhost:8080/myfile.html", in the address box. The page was loaded, but the applet doesn't work. It shows the message saying that "Connection refused: connect". Thanks anyway. --------------- Roda
|
 |
Roda Aing
Greenhorn
Joined: Jul 13, 2004
Posts: 7
|
|
Now, I have found that my code is working with standard http port, 80. But I have another service running on that port. That's why I use port 8080 instead. So, how can I make it work with port 8080? Does this relate to the following line of code? If it does, can you correct the code for me? I don't know how to correct it. I am new to java. Thanks in advance. ==================== Roda
|
 |
Joe Ess
Bartender
Joined: Oct 29, 2001
Posts: 8291
|
|
|
If you look at the documentation for java.net.URL, you will see that it has a number of constructors. You are using the 3-String constructor (String protocol, String host, String file). There is another one that takes 3 strings and a port number. You could also create a URL using a single String object and just concatenate all the parts together (i.e. protocol+host+port+path+file.
|
 |
Roda Aing
Greenhorn
Joined: Jul 13, 2004
Posts: 7
|
|
Yes, your advice is really helpfull. I looked at the documentation and changed my code From: To: It is now working fine with port 8080. So, my problem is fixed. I appreciate all of your help very much, Joe Ess and meimei li. Thanks alot. =============== Roda
|
 |
 |
|
|
subject: Applet and IIS
|
|
|