Connecting a Socket to echo port

Hi,

I am trying to connect to the echo port of my own system. The code I am using is provided here under. When I am executing this I am getting an IOException.

I am running this on Windows XP machine...

I belive this code is working fine when I exectuted on a windows 98 machine..

Pls. suggest if I am doing anything wrong.

Thanks & Regards

G.Vasu

_

******************************************************************************

-

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("127.0.0.1", 7);

out = new PrintWriter(echoSocket.getOutputStream(), true);in = new BufferedReader(new InputStreamReader(

echoSocket.getInputStream()));

} catch (UnknownHostException e) {

System.err.println("Don't know about host you are connecting.");

System.exit(1);

} catch (IOException e) {

System.err.println("Couldn't get I/O for "

+ "the connection to the target systema.");

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();

}

}

Message was edited by:

G.Vasu

[1651 byte] By [G.Vasua] at [2007-11-26 18:32:02]
# 1
Please display and provide the text of the IOException. Never ignore it as you have here in both your catch blocks, always log it.
ejpa at 2007-7-9 6:06:09 > top of Java-index,Archived Forums,Socket Programming...
# 2
HaiThanks for your response.As requested I am placing the exceptionI am getting.. "Couldn't get I/O for the connection to:127.0.0.1"Please help me out of this problem
G.Vasua at 2007-7-9 6:06:09 > top of Java-index,Archived Forums,Socket Programming...
# 3
That's not the text of the IOException, that's the text of your highly uninformative message which I already saw in your source code.The text ('message') of any exception contains valuable information. Always log it, never ignore it.
ejpa at 2007-7-9 6:06:09 > top of Java-index,Archived Forums,Socket Programming...
# 4
Hai..Sorry this is the exception iam gettingjava.net.connectException:connection refused:connectWould be very much thankful for your response.
G.Vasua at 2007-7-9 6:06:09 > top of Java-index,Archived Forums,Socket Programming...
# 5
That means there is nothing listening to that IP address:port. Your system doesn't have an echo server running.
ejpa at 2007-7-9 6:06:09 > top of Java-index,Archived Forums,Socket Programming...
# 6

but when I am pinging to my system the following way

ping 127.0.0.1

I am getting the reply...

C:\Documents and Settings\Administrator>ping 127.0.0.1

Pinging 127.0.0.1 with 32 bytes of data:

Reply from 127.0.0.1: bytes=32 time<1ms TTL=128

Reply from 127.0.0.1: bytes=32 time<1ms TTL=128

Reply from 127.0.0.1: bytes=32 time<1ms TTL=128

Reply from 127.0.0.1: bytes=32 time<1ms TTL=128

Ping statistics for 127.0.0.1:

Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),

Approximate round trip times in milli-seconds:

Minimum = 0ms, Maximum = 0ms, Average = 0ms

Pls. suggest.

G.Vasua at 2007-7-9 6:06:09 > top of Java-index,Archived Forums,Socket Programming...
# 7
'Ping' doesn't prove your host has an echo server running. It only proves it has an IP protocol stack running.
ejpa at 2007-7-9 6:06:09 > top of Java-index,Archived Forums,Socket Programming...