File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes a big problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "a big problem" Watch "a big problem" New topic
Author

a big problem

Naveed Anjum
Greenhorn

Joined: Feb 10, 2004
Posts: 4
import java.net.*;
import java.io.*;
import java.util.*;
public class Client1{
public static void main(String[] args){
String server="localhost";
int port=80;

try{
Socket socket=new Socket(server,port);
BufferedReader inputStream=new BufferedReader(new InputStreamReader(socket.getInputStream()));
PrintWriter outputStream=new PrintWriter(new OutputStreamWriter(socket.getOutputStream()),true);
outputStream.println("Hello");
System.out.println(inputStream.readLine());
socket.close();
Server s=new Server();
}
catch(ConnectException e){System.out.println(e);}
catch(UnknownHostException e){System.out.println(e);}
catch(IOException e){System.out.println(e);}

}
}
when i execute this programme i got an error message"java.net.ConnectionException:Connection refused:connect".Telll me whats the problem with this programme.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24166
    
  30

The exception means, very simply, that there's no server on port 80 of the local host when the client opens a socket.
The line
Server s=new Server();
serves no apparent purpose here. I'm guessing that Server is a class that listens on port 80, and this client is supposed to connect to it. If that's the case, then perhaps you should try creating the server before trying to connect to it.


[Jess in Action][AskingGoodQuestions]
Sloan Bowman
Ranch Hand

Joined: Jan 21, 2003
Posts: 107
As the previous post states there is no web server running on port 80 for you to create a socket connection to. Because of this the exception is being thrown. Try a different server for example www.yahoo.com etc..
 
Consider Paul's rocket mass heater.
 
subject: a big problem
 
Similar Threads
how can i send a file(urgent)
i am in trouble
urgent
Chat At Server Part Both write and read at the same time?
Java Server limit