Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

error when opening a socket in an applet

0 views
Skip to first unread message

CCSAP

unread,
Jan 9, 2001, 6:01:51 AM1/9/01
to
Hi all,
I have some problems when opening a socket in an applet. Basically what i am
trying to do is a program that detects machines which are "alive"; there
will be a server and i am seeking for clients to connect to that server. The
program is extremely simple but i obtain the following error message:

"java.net.ConnectException: Connection refused: no further information
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:312)
at
java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:125)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:112)
at java.net.Socket.<init>(Socket.java:273)
at java.net.Socket.<init>(Socket.java:100)
at Servidor.action(servidor.java:159)
at java.awt.Component.handleEvent(Component.java:3906)
at java.awt.Component.postEvent(Component.java:2790)
at java.awt.Component.postEvent(Component.java:2800)
at java.awt.Component.dispatchEventImpl(Component.java:2607)
at java.awt.Component.dispatchEvent(Component.java:2499)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:319)
at
java.awt.EventDispatchThread.pumpOneEvent(EventDispatchThread.java:103)
at
java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:84)
"
The source is:

import java.applet.Applet;
import java.awt.*;
import java.util.*;
import java.io.*;
import java.net.*;

public class Servidor extends Applet implements Runnable {
Font tit, tit1,nor,cur,neg;
Label titulo, nombre1, nombre2, nombre3, nombre4, nombre5,
nombre6, resultado1, nombres, estados;
Button probar1, probar2, probar3, probar4, probar5,
probar6, continuar, actualizar;
TextField texto1, texto2, texto3, texto4, texto5, texto6,
estado1, estado2, estado3, estado4, estado5, estado6,resultado2;
final static int PUERTO1 = 9003; // puerto de comunicaciones del
servidor
String maquinas[]=new String[10];//ponemos numero inicial de maquinas
String maq_ant[]=new String[10];
//nos permitira comparar los valores de las máquinas con los anteriores
//nos servira para elaborar una cola inicial de maquinas disponibles
private Thread hilo1,hilo2,hilo3,hilo4,hilo5,hilo6;
boolean susp1,susp2,susp3,susp4,susp5,susp6;
Socket sock1,sock2,sock3,sock4,sock5,sock6;
ServerSocket servidor;
int maqtot=0;
// Server server;
// String clientRequest;
// BufferedReader reader;
// PrintWriter writer;
public void init(){
//constructores
tit = new Font ("TimesRoman",Font.BOLD,36);
tit1 = new Font ("TimesRoman",Font.BOLD,24);
nor = new Font ("TimesRoman",Font.PLAIN,18);
cur = new Font ("TimesRoman",Font.ITALIC,18);
neg = new Font ("TimesRoman",Font.BOLD,18);
titulo = new Label("PANTALLA INICIAL");
nombre1 = new Label("Nombre 1 (DNS)");
nombre2 = new Label("Nombre 2 (DNS)");
nombre3 = new Label("Nombre 3 (DNS)");
nombre4 = new Label("Nombre 4 (DNS)");
nombre5 = new Label("Nombre 5 (DNS)");
nombre6 = new Label("Nombre 6 (DNS)");
resultado1 = new Label("Número máquinas disponibles: ");
resultado2 = new TextField(" 0",5);
nombres = new Label("NOMBRES");
estados = new Label("ESTADOS");
probar1 = new Button("Probar");
probar2 = new Button("Probar");
probar3 = new Button("Probar");
probar4 = new Button("Probar");
probar5 = new Button("Probar");
probar6 = new Button("Probar");
// actualizar = new Button("Actualizar"); // por si en un futuro queremos
refrescar
continuar = new Button("Continuar >>");
texto1 = new TextField("",15);
texto2 = new TextField("",15);
texto3 = new TextField("",15);
texto4 = new TextField("",15);
texto5 = new TextField("",15);
texto6 = new TextField("",15);
estado1 = new TextField(" N/A",5);
estado2 = new TextField(" N/A",5);
estado3 = new TextField(" N/A",5);
estado4 = new TextField(" N/A",5);
estado5 = new TextField(" N/A",5);
estado6 = new TextField(" N/A",5);

/*server = new Server (SERVER_PORT);
reader = new BufferedReader (new InputStreamReader (server.in));
writer = new PrintWriter (new OutputStreamWriter (server.out), true);*/

// Configuración de los elementos del GUI Inicial
estado1.setEditable(false);estado2.setEditable(false);
estado3.setEditable(false);estado4.setEditable(false);
estado5.setEditable(false);estado6.setEditable(false);
texto1.setEditable(true);texto2.setEditable(true);
texto3.setEditable(true);texto4.setEditable(true);
texto5.setEditable(true);texto6.setEditable(true);
titulo.setFont(tit);
estado1.setFont(nor);estado2.setFont(nor);
estado3.setFont(nor);estado4.setFont(nor);
estado5.setFont(nor);estado6.setFont(nor);
nombre1.setFont(cur);nombre2.setFont(cur);
nombre3.setFont(cur);nombre4.setFont(cur);
nombre5.setFont(cur);nombre6.setFont(cur);
texto1.setFont(neg);texto2.setFont(neg);texto3.setFont(neg);
texto4.setFont(neg);texto5.setFont(neg);texto6.setFont(neg);
probar1.setFont(neg);probar2.setFont(neg);probar3.setFont(neg);
probar4.setFont(neg);probar5.setFont(neg);probar6.setFont(neg);
nombres.setFont(tit1);
estados.setFont(tit1);
resultado1.setFont(tit1);continuar.setFont(tit1);
resultado2.setFont(tit1);
setLayout(null); //no utilizamos administrador de diseño
//incluimos todos los elementos en el diseño
add(nombre1); add(nombre2); add(nombre3); add(nombre4);
add(nombre5);
add(nombre6);

add(estado1);add(estado2);add(estado3);add(estado4);add(estado5);add(estado6
);
add(nombres); add(estados);

add(probar1);add(probar2);add(probar3);add(probar4);add(probar5);add(probar6
);
add(resultado1); add(resultado2); add(titulo); add(continuar);

add(texto1);add(texto2);add(texto3);add(texto4);add(texto5);add(texto6);
//colocamos lo elementos en su sitio
titulo.reshape(200,10,400,30);nombre1.reshape(50,150,150,20);
nombre2.reshape(50,200,150,20);nombre3.reshape(50,250,150,20);
nombre4.reshape(50,300,150,20);nombre5.reshape(50,350,150,20);
nombre6.reshape(50,400,150,20);
nombres.reshape(225,100,150,30);estados.reshape(600,100,150,30);
texto1.reshape(225,150,150,30);texto2.reshape(225,200,150,30);
texto3.reshape(225,250,150,30);texto4.reshape(225,300,150,30);
texto5.reshape(225,350,150,30);texto6.reshape(225,400,150,30);
probar1.reshape(425,150,100,30);probar2.reshape(425,200,100,30);
probar3.reshape(425,250,100,30);probar4.reshape(425,300,100,30);
probar5.reshape(425,350,100,30);probar6.reshape(425,400,100,30);
estado1.reshape(600,150,150,30);estado2.reshape(600,200,150,30);
estado3.reshape(600,250,150,30);estado4.reshape(600,300,150,30);
estado5.reshape(600,350,150,30);estado6.reshape(600,400,150,30);

resultado1.reshape(25,450,350,40);resultado2.reshape(375,450,100,40);
continuar.reshape(600,450,175,40);
}
// Tratamos por separado cada uno de los eventos
public boolean action (Event e, Object o){
//vemos qué elemento ha generado el evento
if (e.target instanceof TextField){ //evento de Texto
if (e.target == texto1){ //fue el campo1
maquinas[1]=o.toString();
estado1.setText(" PROBAR");
}
if (e.target == texto2){
maquinas[2]=o.toString();
estado2.setText(" PROBAR");
}
if (e.target == texto3){
maquinas[3]=o.toString();
estado3.setText(" PROBAR");
}
if (e.target == texto4){
maquinas[4]=o.toString();
estado4.setText(" PROBAR");
}
if (e.target == texto5){
maquinas[5]=o.toString();
estado5.setText(" PROBAR");
}
if (e.target == texto6){
maquinas[6]=o.toString();
estado6.setText(" PROBAR");
}

}
if (e.target instanceof Button){
if (e.target == probar1){
hilo1=new Thread(this);
try{
hilo1.start();
Socket sock1=new Socket(maquinas[1],PUERTO1);
hilo1.suspend();
estado1.setText("DISPONIBLE");
if (maq_ant[1] != maquinas[1])
maqtot++;
maq_ant[1]=maquinas[1];
}
catch (IOException exc){
exc.printStackTrace();
}
}
if (e.target == probar2){
hilo2=new Thread(this);
try{
hilo2.start();
sock2=new Socket(maquinas[2],PUERTO1);
hilo2.suspend();
estado2.setText("DISPONIBLE");
if (maq_ant[2] != maquinas[2])
maqtot++;
maq_ant[2]=maquinas[2];
}
catch (IOException exc){
exc.printStackTrace();
}
}
if (e.target == probar3){
hilo1=new Thread(this);
try{
hilo3.start();
sock3=new Socket(maquinas[3],PUERTO1);
hilo3.suspend();
estado3.setText("DISPONIBLE");
if (maq_ant[3] != maquinas[3])
maqtot++;
maq_ant[3]=maquinas[3];
}
catch (IOException exc){
exc.printStackTrace();
}
}
if (e.target == probar4){
hilo4=new Thread(this);
try{
hilo4.start();
sock4=new Socket(maquinas[4],PUERTO1);
hilo4.suspend();
estado4.setText("DISPONIBLE");
if (maq_ant[4] != maquinas[4])
maqtot++;
maq_ant[4]=maquinas[4];
}
catch (IOException exc){
exc.printStackTrace();
}
}
if (e.target == probar5){
hilo5=new Thread(this);
try{
hilo5.start();
sock5=new Socket(maquinas[5],PUERTO1);
hilo5.suspend();
estado5.setText("DISPONIBLE");
if (maq_ant[5] != maquinas[5])
maqtot++;
maq_ant[5]=maquinas[5];

}
catch (IOException exc){
exc.printStackTrace();
}
}
if (e.target == probar6){
hilo1=new Thread(this);
try{
hilo6.start();
sock6=new Socket(maquinas[6],PUERTO1);
hilo6.suspend();
estado6.setText("DISPONIBLE");
if (maq_ant[6] != maquinas[6])
maqtot++;
maq_ant[6]=maquinas[6];
}
catch (IOException exc){
exc.printStackTrace();
}
}
}
return true;
}
public void run(){
}

}

I would greatly appreciate if you could help me.
Thanks in advance,
Raúl Sopeña

Helena Hjertén

unread,
Jan 9, 2001, 6:19:18 AM1/9/01
to
Hi Mark,

(please send to the newsgroup next time rather than directly to me)

in the web administration interface to Iplanet4 enterprise server you
activate servlets and set classpaths etc. It is rather simple, but the
documentation isn´t too good. .

Administration webaddress is usually: http://<webservername>:8888 , but you
may have chosen a different port during your installation. From this
interface, click to manage correct server and choose the servlet tag. That
is where you do the settings. These settings can also be done in the
netscape configuration files (.conf) .

All you have to do is
-activate the servlet engine and jsp.
-add the classpath to contain your .jar file.
-call the servlet with http://<webservername>/servlet/packagename.classname
(without .class) in the browser (thus paths is the default invokation). The
servlet name must ofcourse have the same filename as the classname.

I would suggest to read the documentation and configure/run the sample
servlets befoer testing your own. This would make things easier for you.

-----Original Message-----
From: mark.p...@blockbuster.com
[mailto:mark.p...@blockbuster.com]
Sent: Monday, January 08, 2001 11:27 PM
To: hel...@hjerten.com
Subject: iPlanet-WebServer-Enterprise/4.1SP5


Helena,
I saw your Deja post and you seemed to have a knack for explaining
things
in human readible form. I was wondering if I could bother you for some
help.

I have a servlet (developed in VA for Java) that I run on Apache. The
webserver
is NT, so the whole Apache thing doesn't work very well at all. It crashes
every couple of days (It still serves .html, but the servlet ceases to be
available). I stop and restart Apache and everything is all better (I
periodically reboot the server, also). This is NOT the solution I need.

I downloaded iPlanet-WebServer-Enterprise/4.1SP5 and installed their product
on
a test NT server. It serves .html just fine, but I am very confused about
how
to make it recognize my servlet. I created a directory called servlet under
my
docs directory and placed the .jar file there.

Here's the lowdown -
CustomerService.jar contains com.post.customer.service.LoginPage

Here's my current setup -
Servlet Name: CustomerService
Servlet Code (class name): com.post.customer.service.LoginPage
Servlet Classpath:
d:/Netscape/Server4/docs/servlet/CustomerService.jar
Servlet Args:

Any help you could provide would be very appreciated. I think it's
something
simple, but it's whipping me right now.

Mark
(214) 854-3391


ARNO

unread,
Jan 9, 2001, 8:42:17 AM1/9/01
to
I think this is due to limitation on applets. They can only
connect to the server where they originate from (security
issues). So, if you connect to the machine A to get your applet,
you can only open a socket to this machine A.
I hope this is correct...


0 new messages