Port 7 problem

K

Kamil Muzylo

Hello,

I am trying to run simple socket program from Sun's Java Tutorial site but
anytime I try to run it I get Connection Refused error. I tried many
different urls as well as localhost but nothing seemed to work.

Here's the code:

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("taranis", 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: taranis.");
System.exit(1);
} catch (IOException e) {
System.err.println("Couldn't get I/O for "
+ "the connection to: 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();
}
}

I tried this code on a linux machine with the newest Java installed.

Thanks for your help in advance.
 
S

Sudsy

Kamil Muzylo wrote:
I tried this code on a linux machine with the newest Java installed.

Thanks for your help in advance.

That's because Linux, by default, doesn't have the echo service
enabled. Check your /etc/inetd.conf file. To enable, remove the
# at the beginning of the two lines beginning with #echo and
follow the instructions in the file, namely 'killall -HUP inetd'.
 
C

Cyril Mrazek

Hi,
I know nothing about Linux machines, but on a Windows one you should
add your taranis host and its corresponding address into the hosts
file in the system32/drivers/etc directory.

CM
 
T

Tony Morris

Sudsy said:
Kamil Muzylo wrote:


That's because Linux, by default, doesn't have the echo service
enabled. Check your /etc/inetd.conf file. To enable, remove the
# at the beginning of the two lines beginning with #echo and
follow the instructions in the file, namely 'killall -HUP inetd'.

Also, echo is usually on UDP/7 service, you are trying to connect to TCP/7.


--
Tony Morris
(BInfTech, Cert 3 I.T., SCJP[1.4], SCJD)
Software Engineer
IBM Australia - Tivoli Security Software
(2003 VTR1000F)
 
S

Sudsy

Tony said:
Also, echo is usually on UDP/7 service, you are trying to connect to TCP/7.

Tony,
Just for future reference, here's an excerpt from my /etc/inetd.conf
file:

# To re-read this file after changes, just do a 'killall -HUP inetd'
#
#echo stream tcp nowait root internal
#echo dgram udp wait root internal

Many of the basic services are supported by both protocols.
 
K

Kamil Muzylo

Thank you for help.
Sudsy said:
TCP/7.

Tony,
Just for future reference, here's an excerpt from my /etc/inetd.conf
file:

# To re-read this file after changes, just do a 'killall -HUP inetd'
#
#echo stream tcp nowait root internal
#echo dgram udp wait root internal

Many of the basic services are supported by both protocols.
 

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,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top