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 8963913
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:27:53+00:00 2026-06-15T16:27:53+00:00

Hello guys I am trying to do an echo Server by java but it

  • 0

Hello guys I am trying to do an echo Server by java but it is nnot working .. .I don’t know why .. but it seems like the server is waiting the client and the client is waiting the server … so they can’t deliver the infromation to each other ..

here is the code
for the Server

    ServerSocket server = null;
        try {
             server = new ServerSocket(3333);
              System.out.println("Listening on 3333");
    } catch (IOException ex) {
        System.out.println("Error can't connect to 3333");
        System.exit(1);
    }

        Socket clientSocket = null;
    try {
        clientSocket = server.accept();
    } catch (IOException ex) {
        System.out.println("Accept fail");
        System.exit(1);
    }
    PrintWriter out = null;
    try {
         out = new PrintWriter(clientSocket.getOutputStream());
    } catch (IOException ex) {
        Logger.getLogger(JavaApplication20.class.getName()).log(Level.SEVERE, null, ex);
    }
    BufferedReader br = null;
    try {
        br = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
    } catch (IOException ex) {
        Logger.getLogger(JavaApplication20.class.getName()).log(Level.SEVERE, null, ex);
    }
    BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in));

    String inputLine, outputLine;
 while(!(inputLine=br.readLine()).equals("bye"))
            {
                out.print("echo: " + inputLine);

            }
    out.close();
    br.close();
    clientSocket.close();
    server.close();
    System.out.println("Server Exited");

and here is the code for the client

 Socket client = null;
   try {
        client = new Socket("localhost", 3333);
        System.out.println("Connected on 3333");
    } catch (UnknownHostException ex) {
        System.out.println("Couldn't connect to the server");
        System.exit(1);
    } catch (IOException ex) {
        Logger.getLogger(KnockKnockClient.class.getName()).log(Level.SEVERE, null, ex);
    }


    PrintWriter out = null;
    BufferedReader in = null;
    BufferedReader stdIn = null;

    try {
        out = new PrintWriter(client.getOutputStream(), true);
    } catch (IOException ex) {
        Logger.getLogger(KnockKnockClient.class.getName()).log(Level.SEVERE, null, ex);
    }
    try {
        in = new BufferedReader(new InputStreamReader(client.getInputStream()));
    } catch (IOException ex) {
        Logger.getLogger(KnockKnockClient.class.getName()).log(Level.SEVERE, null, ex);
    }
    stdIn = new BufferedReader(new InputStreamReader(System.in));

    String fromServer, fromUser;


    while((fromUser=stdIn.readLine())!=null)
        {
            System.out.println("From user: "+ fromUser);

            out.print(fromUser);
            fromServer=in.readLine();
            System.out.println(fromServer);
        }



    out.close();
    stdIn.close();
    in.close();
    client.close();

    System.out.println("client Exited");

Any Help with that ??

  • 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-15T16:27:54+00:00Added an answer on June 15, 2026 at 4:27 pm

    You’re sending some string from the client ("Hello" for example), and you’re trying to read it with readLine() on the server (and vice versa). readLine() will only return once it finds an EOL character, or once the input stream is closed.

    Since the client doesn’t send any EOL char, the server waits indefinitely, and the client also because it waits for the answer from the server.

    Send "Hello\n", and it will work better.

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

Sidebar

Related Questions

hello guys I am trying to extract all the anchor links from aol but
Hello guys, I have been trying to implement the DSUM function but failed to
Hello guys i`m trying to delete a row in a access database but when
Hello guys and girls im trying to a sql update but think i forgot
I'm trying to send XML doc to server from client. But when server get
hello guys i am trying to print title from a set of urls in
Hello guys i'm facing a isolated exception when trying to edit my UI it
Hello guys look to my code I'm trying to make a program which asks
Hello guys I can't provide the code but you can see it on the
Hello guys Im trying to set a max width and height so that when

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.