java.net.ConnectException: Connection timed out: connect

G

Guy Ka

Hi,
I have the following piece of code mostly from the java tutorial at
http://web2.java.sun.com/docs/books/tutorial/networking/sockets/readingWriting.html
When running this code, I get the ConnectException error. I can actually
ping all the IP addresses that I assign to the variable "myhost" (one of
them is my locoal machine). Two of these machines run WinXp while one of
them runs WinM. Do I need special user rights to access the echo service
under windows?
Thanks for any hint. Guy



import java.net.*;
import java.io.*;
public class EchoClien{
public static void main (String [] args) throws IOException {
Socket echo_socket = null;
PrintWriter out = null;
BufferedReader in = null;
String Etoile = "192.168.1.101";
String Terre = "192.168.1.102";
String Soleil = "192.168.1.100";
String myhost = Terre;

try{
echo_socket = new Socket (myhost, 7);
out = new PrintWriter(echo_socket.getOutputStream(),true);
in = new BufferedReader(new
InputStreamReader(echo_socket.getInputStream()));
}catch (UnknownHostException e) {
System.err.println("Don't know about host: " + myhost);
System.exit(1);
} catch (IOException e) {
System.out.println(e);
System.err.println("Couldn't get I/O for "
+ "the connection to: " + myhost);
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();
echo_socket.close();

}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,140
Latest member
SweetcalmCBDreview
Top