?
Solved

connectException:Connection refused

Posted on 2003-03-26
24
Medium Priority
?
395 Views
Last Modified: 2007-12-19
When i tried loading the html file to the intranet , i had the error ..connectException:Connection refused.


0
Comment
Question by:Jasbir21
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 14
  • 6
  • 3
  • +1
24 Comments
 

Author Comment

by:Jasbir21
ID: 8214560
I think i know the reason but i am not sure, i mean if i am doing something on perl script and html , the perl script has to be done in (cgi-bin)  var/www/cgi-bin.

And the html file is loaded in the html folder, cd /var/www/html.

....Is there such thing as java-bin in java.???


Thanks
0
 
LVL 4

Expert Comment

by:kokchoon78
ID: 8214648
>....Is there such thing as java-bin in java.???

i don't think any web server have the java-bin folder to serve the jsp or servlet. Correct me if i am wrong.

JSP and servlet must run on a servlet container, for example tomcat, which will then integrate with your web server, for example Apache web server. For more information, you may visit :

http://jakarta.apache.org/tomcat/index.html

hth,
Kok Choon.

0
 

Author Comment

by:Jasbir21
ID: 8214696
Actually , mine is a java program that stays on  the intranet.That application is connected to oracle using jdbc.And then the applet is connected to application using sockets.

....I thought since i am not jsp , i might not need that..

Sorry, i am a bit confuse.

Jasbir
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:Jasbir21
ID: 8215033
HELP , i don't know what to do
0
 

Author Comment

by:Jasbir21
ID: 8215352
I am getting another error , Exception in thread "main" java. lang.InternalError:Can't connecct to x11 window server using '0:0' as the value of the DISPLAy.

0
 
LVL 4

Expert Comment

by:kokchoon78
ID: 8215388
ic, then mind to post your applet ?
0
 
LVL 4

Expert Comment

by:kokchoon78
ID: 8215403
and also the application on intranet ?
0
 

Author Comment

by:Jasbir21
ID: 8215512
The applicatin code for the server :



import java.sql.*;
import java.util.Properties;
import java.io.*;
import java.net.*;

public class CommentsServer extends Thread {
  public static final int DEFAULT_PORT = 7777;
  protected int port;
  protected ServerSocket server;
 
   String username ="combtest";
   String password = "combtest";
 
  public static void main (String args[]) {
    int port=0;
    if (args.length == 1) {
      try {
        port = Integer.parseInt (args[0]);
      } catch (NumberFormatException e) { }
    }
    try {
          Class.forName("oracle.jdbc.driver.OracleDriver");

String sourceURL ="jdbc:oracle:thin:@klmsph1:1521:KLM";

String user="combtest";

String password="combtest";

    }
    catch (Exception e) {
      System.err.println("Failed to load JDBC driver.");
      System.exit (1);
    }
 
    new CommentsServer (port);
  }
  public CommentsServer (int port) {
    super ("Comments Server");
    if (port == 0)
      port = DEFAULT_PORT;
    this.port = port;
    try {
      server = new ServerSocket (port);
    } catch (IOException e) {
      System.err.println ("Error creating server");
      System.exit (1);
    }
    start();
  }
  public void run() {
    System.out.println ("Server Running");
    ThreadGroup connections = new ThreadGroup ("Comment Connections");
    connections.setMaxPriority(this.getPriority()-1);
    try {
      while (true) {
        Socket client = server.accept();
        System.out.println ("Connection from: " + client.getInetAddress().getHostName());
        CommentsConnection c = new CommentsConnection (connections, client);
      }
    } catch (IOException e) {
      System.err.println ("Exception listening");
      System.exit (1);
    }
    System.exit (0);
  }
}

class CommentsConnection extends Thread {
  static int counter = 0;
  protected ObjectInputStream in;
  protected PrintWriter out;
  public CommentsConnection (ThreadGroup group, Socket client) {
    super (group, "Connection " + counter++);
    try {
      in = new ObjectInputStream (client.getInputStream ());
      out = new PrintWriter (client.getOutputStream(), true);
    } catch (IOException e) {
      try {
        client.close();
      } catch (IOException e2) { }
      System.err.println ("Unable to connect.");
      return;
    }
    start();
  }



  public void run () {
    try {
      String mode = (String)in.readObject();
      if (mode.equals("insert")) {
            
            String name=(String)in.readObject();
     
        try {
              String u="jdbc:oracle:thin:@klmsph1:1521:KLM";
              Connection con=DriverManager.getConnection(u,"combtest","combtest");
              PreparedStatement prep=con.prepareStatement("Insert into TEST values(?)");
              prep.setString(1,name);
       
              if(prep.executeUpdate()!=1)
              throw new Exception("Bad update");
       
         
        } catch (Exception e) {
          out.println ("Error updating: " + e);
          return;
        }
      } else if (mode.equals("query")) {
        try {
              
              Connection con=DriverManager.getConnection("jdbc:oracle:thin:@klmsph1:1521:KLM","combtest","combtest");
          Statement statement=con.createStatement();
         
          ResultSet result=statement.executeQuery("SELECT * FROM TEST");
         
          out.println("Name");
         
          int nameCol=result.findColumn("NAME");
         
         
          String name,user,comments;
         
          while(result.next())
          {
                
                name=result.getString(nameCol);
       
                
                out.println(name);
          }
          statement.close();
          con.close();
         
         
        } catch (Exception e) {
          out.println ("Error querying: " + e);
          return;
        }
      } else {
        out.println ("Invalid Command: " + mode);
      }
    } catch (Exception e) {
      out.println ("Error reading Stream: " + e);
    }
    out.close();
  }
}

The applet code is:
import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;
import java.io.*;
import java.net.*;
/*<applet
code=j
width = 400
height = 400
>
</applet>

*/

public class j extends Applet{


TextArea ta;
TextField name;
Panel p1,p2;
Button q,i;
Panel p3;
public void init(){


p1=new Panel(new BorderLayout());
q=new Button("Query");
p1.add(q,"South");
ta=new TextArea();
ta.setEditable(false);
p1.add(ta,"Center");
add(p1);
p2=new Panel(new BorderLayout());
i=new Button("Insert");
p2.add(i,"South");
p3=new Panel();

name=new TextField(" ",10);

p3.add(name);

p2.add(p3,"Center");


add(p2);
}
public void run_S(){

ByteArrayOutputStream bao=new ByteArrayOutputStream();
com cc=new com("sentri.com",0,bao,name.getText());
ta.setText(bao.toString());
}

public boolean action(Event e,Object o){

if(e.target==i){
run_S();
return true;
}

else if(e.target==q){

run_q();
return true;
}

else return false;

}

public void run_q(){
ByteArrayOutputStream bao=new ByteArrayOutputStream();
com cc=new com("sentri.com",0,bao);
ta.setText(bao.toString());
}




class com{

 int PORT=7777;
private static final String query="query";
private static final String insert="insert";
private String host=null;
private OutputStream os=null;
public String n="null";
private int port=0;

 com(String host,int port,OutputStream os,String name){

this.host=host;
this.port=((port==0)?PORT:port);
this.os=os;
insert(name);
run(name);
}

com(String host,int port,OutputStream os){
this.host=host;
this.port=((port==0)?PORT:port);
this.os=os;
query();
}
 private void query () {
    PrintWriter out = new PrintWriter (os, true);
    try {
      Socket s = new Socket (host, PORT);
      ObjectOutputStream oos = new ObjectOutputStream (s.getOutputStream());
   
      oos.writeObject (query);
      oos.flush();
      BufferedReader in = new BufferedReader (new InputStreamReader (s.getInputStream()));
      String line;
      while ((line = in.readLine()) != null) {
        out.println (line);
      }
      out.close();
      s.close();
    } catch (IOException e) {
      out.println ("Error querying." + e);
      return;
    }
  }


public void run(String name){
n=name;
}
  private void insert (String name) {
    PrintWriter out = new PrintWriter (os, true);
    try {
      Socket s = new Socket (host, PORT);
      ObjectOutputStream oos = new ObjectOutputStream (s.getOutputStream());
      oos.writeObject (insert);
      oos.writeObject (name);
     
      oos.flush();
      BufferedReader in = new BufferedReader (new InputStreamReader (s.getInputStream()));
      String line;
      while ((line = in.readLine()) != null) {
        out.println (line);
      }
      oos.close();
      s.close();
    } catch (IOException e) {
      out.println ("Error inserting." + e);
      return;
    }
  }
 

 void main(String args[]){
 args[0]=n;

if(args.length==1)
{
com cc=new com("sentri.com",0,System.out,args[0]);
//return true;

}

else if(args.length==0)
{
com cc=new com("sentri.com",0,System.out);
}

//return false;


}

}

}


the html file:
<html>
<body>
<hr>
<applet
code=j.class
width = 200
height = 200
>
</applet>
<hr>
</body>
</html>





0
 
LVL 4

Expert Comment

by:kokchoon78
ID: 8215871
Hi,

   i think u need to use ip instead of "sentri.com", and i also made some changes on the j.java :

import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;
import java.io.*;
import java.net.*;
/*<applet
code=j
width = 400
height = 400
>
</applet>

*/

public class j extends Applet implements ActionListener
{

      TextArea ta;
      TextField name;
      Panel p1,p2;
      Button q,i;
      Panel p3;

      public void init()
      {

            p1=new Panel(new BorderLayout());
            q=new Button("Query");
            p1.add(q,"South");
            ta=new TextArea();
            ta.setEditable(false);
            p1.add(ta,"Center");
            add(p1);
            p2=new Panel(new BorderLayout());
            i=new Button("Insert");
            p2.add(i,"South");
            p3=new Panel();

            name=new TextField(" ",10);
            p3.add(name);
            p2.add(p3,"Center");
            add(p2);

            q.addActionListener(this);
            i.addActionListener(this);
      }

      public void run_S()
      {

            ByteArrayOutputStream bao=new ByteArrayOutputStream();
                //Pls change to server's ip
            com cc=new com("203.127.231.71",0,bao,name.getText());
            ta.setText(bao.toString());
      }

      public void actionPerformed(ActionEvent action)
      {
            if(action.getActionCommand().equals("Insert"))
            {
                  run_S();
            }
            else if(action.getActionCommand().equals("Query"))
            {
                  run_q();
            }
      }


      public void run_q()
      {
            ByteArrayOutputStream bao=new ByteArrayOutputStream();
                //Pls change to server's ip
            com cc=new com("203.127.231.71",0,bao);
            ta.setText(bao.toString());
      }


class com
{

int PORT=7777;
private static final String query="query";
private static final String insert="insert";
private String host=null;
private OutputStream os=null;
public String n="null";
private int port=0;

com(String host,int port,OutputStream os,String name)
{
this.host=host;
this.port=((port==0)?PORT:port);
this.os=os;
insert(name);
run(name);
}

com(String host,int port,OutputStream os)
{
this.host=host;
this.port=((port==0)?PORT:port);
this.os=os;
query();
}

private void query ()
{
   PrintWriter out = new PrintWriter (os, true);
   try {
     Socket s = new Socket (host, PORT);
     ObjectOutputStream oos = new ObjectOutputStream (s.getOutputStream());

     oos.writeObject (query);
     oos.flush();
     BufferedReader in = new BufferedReader (new InputStreamReader (s.getInputStream()));
     String line;
     while ((line = in.readLine()) != null) {
       out.println (line);
     }
     out.close();
     s.close();
   } catch (IOException e) {
     out.println ("Error querying." + e);
     return;
   }
 }


public void run(String name)
{
n=name;
}

private void insert (String name)
{
   PrintWriter out = new PrintWriter (os, true);
   try {
     Socket s = new Socket (host, PORT);
     ObjectOutputStream oos = new ObjectOutputStream (s.getOutputStream());
     oos.writeObject (insert);
     oos.writeObject (name);

     oos.flush();
     BufferedReader in = new BufferedReader (new InputStreamReader (s.getInputStream()));
     String line;
     while ((line = in.readLine()) != null) {
       out.println (line);
     }
     oos.close();
     s.close();
   } catch (IOException e) {
     out.println ("Error inserting." + e);
     return;
   }
 }


void main(String args[]){
args[0]=n;

if(args.length==1)
{
com cc=new com("sentri.com",0,System.out,args[0]);
//return true;

}

else if(args.length==0)
{
com cc=new com("sentri.com",0,System.out);
}

//return false;


}

}

}


j.html:

<html>
<body>
<hr>
<applet code=j.class width=500 height=300></applet>
<hr>
</body>
</html>



p/s: i didn't make any changes on CommentsServer.java

hth,
Kok Choon.

 
0
 

Author Comment

by:Jasbir21
ID: 8215953


 i still get the error. ..just to make sure to get the ip of sentri is it ping sentri
0
 
LVL 4

Expert Comment

by:kokchoon78
ID: 8216165
Hello,

  i use tracert and got the ip : 216.147.205.40, but i fail to connect to that server, because i don't have permission to access / connect the server. Try to ask your system admin to give access for you to connect the server.

regards,
Kok Choon.
0
 

Author Comment

by:Jasbir21
ID: 8216389
Ok, i will try that
0
 

Author Comment

by:Jasbir21
ID: 8216426
couldn't ask the permission.But when i tried to connect using the sentri... , the full applet was  loaded.When i clicked on the query button, nothing came out.But it was as if , the querry button became stagnant.Meaning not moving
Regards,
Jasbir

0
 
LVL 4

Expert Comment

by:kokchoon78
ID: 8216524
I think the server is restricted from access by a applet, have u tested run the server application on your pc, then run your applet to connect it ? (Just change the ip address to your mechine's ip), if that work, means there are nothing wrong on the code. Try to ask for permission to connect to the server (Sentri.com).

regards,
Kok Choon.
0
 

Author Comment

by:Jasbir21
ID: 8216621
couldn't ask the permission.But when i tried to connect using the sentri... , the full applet was  loaded.When i clicked on the query button, nothing came out.But it was as if , the querry button became stagnant.Meaning not moving
Regards,
Jasbir

0
 
LVL 86

Expert Comment

by:CEHJ
ID: 8216903
The applet will have to be loaded from the same server to which it's trying to make a JDBC connection
0
 

Author Comment

by:Jasbir21
ID: 8222253
..... The applet is loaded from the same server to which it's trying to make a JDBC connection .......

It 's funny that java is installed in the server, but the plug-in is not.Surprisingly.......I know plug-in is not installed on the intranet, coz i get a blank screen when


0
 
LVL 9

Accepted Solution

by:
Venci75 earned 800 total points
ID: 8223204
hmm...
If it was secutity issue - a SecurityException would be thrown. 'Connection refused' is thrown when there is no server socket open  on the machine - you are trying to connect, or if you are behind a firewall and there are restrictions for this host/port.
Can you try these from your machine:
telnet 203.127.231.71 7777
telnet sentri.com 7777
telnet klmsph1 1521

and post here whether you ware able to connect?
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 8223708
I won't continue with your last comment, Jasbir21, as you should tackle one problem at a time. Try Venci75's suggestions first.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 8223710
>>as you should tackle one problem at a time

Also, the *immediate* problem sounds like a network one ;-)
0
 

Author Comment

by:Jasbir21
ID: 8229219
I am still unable to connect.I thought , maybe the plug-in is not installed properly, that's why I am unable to connect( meaning view the applet).


 
 
0
 

Author Comment

by:Jasbir21
ID: 8229225
If the reason is becoz of networking, maybe i should talk to the admin and see if i am blocked from connecting.
..Anywhere, i am in the firewall.

Thanks
0
 

Author Comment

by:Jasbir21
ID: 8229242
Hey, got the answer.I was blocked from connecting.It was a network issue and not the plug-in.
 Thanks a lot,couldn't have done it without your help.

....I am posting a another question call "writing code of a bar scanner in java".I know nothing of writing code of a scanner.I would appreciate it very much if any of you could post any links or anything that  at the question that might help me to write the bar scanner code.

Plsssssssssssss visit that question.

Thanks,
Jasbir  
0
 

Author Comment

by:Jasbir21
ID: 8229245
Thanks .
...God bless
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This video teaches viewers about errors in exception handling.
Suggested Courses
Course of the Month14 days, 3 hours left to enroll

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question