| | |
java.net.ConnectException: Connection refused
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
new to network stuff going through the java tutorials and i did what it said heres the code:
bill-laptop is the name of the computer that i am trying to run this on here is the stack trace:
running on a vista :-( but the laptop is brand new duel-core :-)
any advise
java Syntax (Toggle Plain Text)
import java.io.*; import java.net.*; public class EchoClient { public static void main(String[] args) throws IOException { Socket echoSocket = null; PrintWriter out = null; BufferedReader in = null; try { echoSocket = new Socket("bill-laptop", 7); try{ out = new PrintWriter(echoSocket.getOutputStream(), true); } catch (IOException e) { System.err.println("Couldn't get I/O for " + "the connection to: OUT."); System.exit(1); } try{ in = new BufferedReader(new InputStreamReader( echoSocket.getInputStream())); } catch (IOException e) { System.err.println("Couldn't get I/O for " + "the connection to: IN."); System.exit(1); } } catch (UnknownHostException e) { System.err.println("Don't know about host: taranis."); System.exit(1); } BufferedReader stdIn = new BufferedReader( new InputStreamReader(System.in)); String userInput; while ((userInput = stdIn.readLine()) != null) { out.println(userInput); System.out.println("echo: " + in.readLine()); } out.close(); in.close(); stdIn.close(); echoSocket.close(); } }
bill-laptop is the name of the computer that i am trying to run this on here is the stack trace:
Java Syntax (Toggle Plain Text)
java.net.ConnectException: Connection refused: connect at java.net.PlainSocketImpl.socketConnect(Native Method) at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333) at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195) at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182) at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366) at java.net.Socket.connect(Socket.java:519) at java.net.Socket.connect(Socket.java:469) at java.net.Socket.<init>(Socket.java:366) at java.net.Socket.<init>(Socket.java:180) at EchoClient.main(EchoClient.java:12)
running on a vista :-( but the laptop is brand new duel-core :-)
any advise
My site, random PM's from people I haven't hear from before will be DELETED
"If people are good only because they fear punishment, and hope for reward, then we are a sorry lot indeed.",
"If we knew what it was we were doing, it would not be called research, would it? "-Albert Einstein
"If people are good only because they fear punishment, and hope for reward, then we are a sorry lot indeed.",
"If we knew what it was we were doing, it would not be called research, would it? "-Albert Einstein
thanks for the reply
i tried it, but it didn't work
i tried it, but it didn't work
My site, random PM's from people I haven't hear from before will be DELETED
"If people are good only because they fear punishment, and hope for reward, then we are a sorry lot indeed.",
"If we knew what it was we were doing, it would not be called research, would it? "-Albert Einstein
"If people are good only because they fear punishment, and hope for reward, then we are a sorry lot indeed.",
"If we knew what it was we were doing, it would not be called research, would it? "-Albert Einstein
For running the program mentioned, you need an echo server running on your system, which is provided by most UNIX machines and runs on port no 7.
To check if your Vista box has one running just hit
Now this prob would have occurred if we were trying to create a
To check if your Vista box has one running just hit
telnet localhost 7 , if it shows connection refused or could not connect, then it means you box does not have an echo server, and hence your program will not work and thats the reason I feel for your ConnectException exception.•
•
•
•
I know that your tutorial probably says to connect to port 7 for an echo, but try connecting to a port > 1024. Chances are your errors are due to trying to connect to a port that is in use.
ServerSocket on the given port, But as we are creating a client socket here to connect on the given port we apparently want the opposite, that is the port should be in use by the "echo server" so that we can connect to it. Last edited by stephen84s; Jun 28th, 2008 at 6:36 am. Reason: Spell mistakes
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand."
"How to ask questions the smart way ?"
"How to ask questions the smart way ?"
•
•
Join Date: Jul 2008
Posts: 1
Reputation:
Solved Threads: 1
I too have the same problem.If u get any solution pls let me.
•
•
•
•
new to network stuff going through the java tutorials and i did what it said heres the code:
java Syntax (Toggle Plain Text)
import java.io.*; import java.net.*; public class EchoClient { public static void main(String[] args) throws IOException { Socket echoSocket = null; PrintWriter out = null; BufferedReader in = null; try { echoSocket = new Socket("bill-laptop", 7); try{ out = new PrintWriter(echoSocket.getOutputStream(), true); } catch (IOException e) { System.err.println("Couldn't get I/O for " + "the connection to: OUT."); System.exit(1); } try{ in = new BufferedReader(new InputStreamReader( echoSocket.getInputStream())); } catch (IOException e) { System.err.println("Couldn't get I/O for " + "the connection to: IN."); System.exit(1); } } catch (UnknownHostException e) { System.err.println("Don't know about host: taranis."); System.exit(1); } BufferedReader stdIn = new BufferedReader( new InputStreamReader(System.in)); String userInput; while ((userInput = stdIn.readLine()) != null) { out.println(userInput); System.out.println("echo: " + in.readLine()); } out.close(); in.close(); stdIn.close(); echoSocket.close(); } }
bill-laptop is the name of the computer that i am trying to run this on here is the stack trace:
Java Syntax (Toggle Plain Text)
java.net.ConnectException: Connection refused: connect at java.net.PlainSocketImpl.socketConnect(Native Method) at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333) at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195) at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182) at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366) at java.net.Socket.connect(Socket.java:519) at java.net.Socket.connect(Socket.java:469) at java.net.Socket.<init>(Socket.java:366) at java.net.Socket.<init>(Socket.java:180) at EchoClient.main(EchoClient.java:12)
running on a vista :-( but the laptop is brand new duel-core :-)
any advise
Have you tried what I had mentioned in my previous post ?????
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand."
"How to ask questions the smart way ?"
"How to ask questions the smart way ?"
thanks for the replies,
telnet? i've never used telnet, is it command prompt? if so this doesn't have it, sorry for my ignorance
i think it may just be vista refusing the VM access, but other things that use java.net will run
telnet? i've never used telnet, is it command prompt? if so this doesn't have it, sorry for my ignorance
i think it may just be vista refusing the VM access, but other things that use java.net will run
My site, random PM's from people I haven't hear from before will be DELETED
"If people are good only because they fear punishment, and hope for reward, then we are a sorry lot indeed.",
"If we knew what it was we were doing, it would not be called research, would it? "-Albert Einstein
"If people are good only because they fear punishment, and hope for reward, then we are a sorry lot indeed.",
"If we knew what it was we were doing, it would not be called research, would it? "-Albert Einstein
ok i figured out telnet and
telnet localhost 7 did give connection failed, so what should i do to get an echo server running? Last edited by sciwizeh; Jul 18th, 2008 at 11:56 am.
My site, random PM's from people I haven't hear from before will be DELETED
"If people are good only because they fear punishment, and hope for reward, then we are a sorry lot indeed.",
"If we knew what it was we were doing, it would not be called research, would it? "-Albert Einstein
"If people are good only because they fear punishment, and hope for reward, then we are a sorry lot indeed.",
"If we knew what it was we were doing, it would not be called research, would it? "-Albert Einstein
•
•
Join Date: Jun 2008
Posts: 8
Reputation:
Solved Threads: 1
I used your code and executed it with localhost (as name of my computer) and the port 4000.
echoSocket = new Socket("localhost", 4000);
It works without errors.
you can use code for server like this:
echoSocket = new Socket("localhost", 4000);
It works without errors.
you can use code for server like this:
Java Syntax (Toggle Plain Text)
try{ serverSocket = new ServerSocket(4000); } catch (IOException e) { System.err.println("Could not listen on port: 4000."); System.exit(1); } Socket clientSocket = null; try { clientSocket = serverSocket.accept(); } catch (IOException e) { System.err.println("Accept failed."); System.exit(1); } out = new DataOutputStream(clientSocket.getOutputStream()); is = clientSocket.getInputStream();
Last edited by Tekmaven; Jul 18th, 2008 at 6:15 pm. Reason: Code tags
![]() |
Similar Threads
- Rmi by Internet connection (Java)
- ping is not successful. (Java)
- Need Urgent help with Novell (IT Professionals' Lounge)
- JDBC and MYSQL database (Java)
- JNDI/JDBC lookup problem with Sun Java Application Server 8.2 (Java)
- Problem in running a simple session bean in JOnAS (Java)
- applet not connecting (Java)
- Problem with Axis (Java)
Other Threads in the Java Forum
- Previous Thread: Icons not showing?
- Next Thread: i need urgent help. this error cmoing. i dont know what to do
Views: 17549 | Replies: 19
| Thread Tools | Search this Thread |
Tag cloud for Java
3d @param affinetransform android api apple applet application arc arguments array arrays automation binary bluetooth byte c# chat class classes click client code compare component corrupted database detection draw eclipse error event exception file fractal game givemetehcodez graphics gui guitesting helpwithhomework html ide image input integer j2me java java.xls javaprojects jmf jni jpanel julia keytool linux list loop map method methods mobile netbeans newbie number object oracle os pong print problem producer program programming project projectideas read recursion reflection replaysolutions rim scanner screen server set size sms socket sort sql string swing terminal test threads time transfer tree web windows






