Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8093529
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T20:31:20+00:00 2026-06-05T20:31:20+00:00

I’ve just started with this section of the tutorial. I only have a basic

  • 0

I’ve just started with this section of the tutorial. I only have a basic understanding of what ports are, etc.

I tried to run this 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();
    }
}

“Don’t know about host: taranis.
Java Result: 1”

Is the error catch I get. From my limited understanding; is the echo-server something which exists on my machine? If that’s the case, what do I need to do to get this running? Or am I way off?
Also why have they chosen “taranis” as a parameter?

Ive also replaced “taranis” with “localhost” to see what happened.
It ended up catching an IOException this time.

EDIT: So I’ve found that the echo server is disabled by default in win7 and have activated it. However I cant even connect to it on telnet. I think I may just be in over my head. I’ve also tried the sockets you have recommended with no success.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T20:31:21+00:00Added an answer on June 5, 2026 at 8:31 pm

    From the same tutorial:

    … The Socket constructor used here requires the name of the machine and the port number to which you want to connect. The example program uses the host name taranis. This is the name of a hypothetical machine on our local network. When you type in and run this program on your machine, change the host name to the name of a machine on your network. Make sure that the name you use is the fully qualified IP name of the machine to which you want to connect. The second argument is the port number. Port number 7 is the port on which the Echo server listens.`

    In any case, you will probably want to change taranis to "localhost" and make sure an echo service is running on your machine. If it’s not, you could use something like the following code to simulate an echo server.

    import java.net.Socket;
    import java.util.Formatter;
    import java.util.Scanner;
    import java.io.IOException;
    import java.net.ServerSocket;
    import java.util.ArrayList;
    import java.util.concurrent.ExecutorService;
    import java.util.concurrent.Executors;
    
    public class EchoServer {
    
        public static void main(String[] args) {
            try {
                new EchoServer(INSERTPORT).execute();
            } catch (IOException e) {
                e.printStackTrace();
                System.exit(1);
            }
        }
    
        private ServerSocket serverSocket;
        private int port;
    
        private ArrayList<Client> clientList;
        private ExecutorService clientRunner;
    
        public EchoServer(int port) throws IOException {
            this.port = port;
            serverSocket = new ServerSocket(port);
            clientRunner = Executors.newCachedThreadPool();
            clientList = new ArrayList<>();
        }
    
        public void sendMessageToAll(String message) {
            for (Client c : clientList) {
                c.displayMessage(message);
            }
        }
    
        public void execute() throws IOException {
            while (true) {
                clientList.add(new Client(serverSocket.accept(), this));
                clientRunner.execute(clientList.get(clientList.size()-1));
            }
        }
        private class Client implements Runnable {
    
            private Socket clientSocket;
            private Scanner input;
            private Formatter output;
    
            public Client(Socket s) throws IOException {
                clientSocket = s;
    
                input = new Scanner(clientSocket.getInputStream());
                output = new Formatter(clientSocket.getOutputStream());
            }
    
            public void displayMessage(String s) {
                output.format(s + "\n");
                output.flush();
            }
            @Override
            public void run() {
                while(clientSocket.isConnected()) {
                    if(input.hasNextLine()) {
                        sendMessageToAll(input.nextLine());
                    }
                }
            }
        }
    }
    

    Edit: Just for completeness, as you mentioned some problems running the code, you run the server (this code) and leave it running in the background, then run the client (the code you posted). I tested it, works fine.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have some data like this: 1 2 3 4 5 9 2 6
For some reason, after submitting a string like this Jack’s Spindle from a text
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a jquery bug and I've been looking for hours now, I can't

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.