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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T06:38:25+00:00 2026-06-12T06:38:25+00:00

I have made a java ServerSocket. I send a request to it using a

  • 0

I have made a java ServerSocket. I send a request to it using a Socket Object. The request is delivered to the ServerSocket but the response does not come back.

Server Code :

                Socket startserver = this.wifiserver.accept();

                in = new InputStreamReader(startserver.getInputStream());
                BufferedReader read = new BufferedReader(in);
                String request = read.readLine();
                //System.out.println(request);

                if(request.equals("SNDKEY")){
                    System.out.println("Command is: SNDKEY");
                    out = new PrintWriter(startserver.getOutputStream());
                    out.print("12345678901234567890");
                    out.close();

                }

Client Code:

        Socket connection = new Socket( ip, port );
        writeServer = new PrintWriter(connection.getOutputStream());
        inputStream = new InputStreamReader(connection.getInputStream());
        bufferStream = new BufferedReader(inputStream);
        writeServer.print("SNDKEY");


        this.Key = bufferStream.readLine();

The problem is that the program gets stuck at the command bufferStream.readLine(). I have checked that the request is reaching the server by outputing the line command is: SNDKEY and it always gets printing out. But the key is never received at the user end.

  • 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-12T06:38:26+00:00Added an answer on June 12, 2026 at 6:38 am

    bufferStream.readLine() blocks until a newline is received. But on the server side you are outputting with PrintWriter.print(), which doesn’t send any newlines unless you tell it to. So the client waits forever. Either change the print to println, or add a newline character to the end of the message:

    out.print("12345678901234567890\n"); 
    

    When you don’t want to use newlines in your protocol, you could alternatively use bufferStream.read instead of bufferStream.readLine to return after reading each byte or after reading a specific number of bytes.

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

Sidebar

Related Questions

I have made an application using Java/Hibernate/MySQL, but whenever I try running it, it
i have made a web application using java pages with eclipse. But i have
i have made a urdu editor using swing in java and now wana add
I have made accelerators in my java gui by using setAccelerator(), and they work
I have read that generally abstract classes should not be made Serializable in Java.
I have made a java socket listener which listens on port 80. And what
I have a project made using Java. I have a complex processing, something like
I am using wicket framework, and I have made a zip file by Java
I have made a program in Java that calculates powers of two, but it
I have made an Axis2 Web Service in Java. I am using Apache Tomcat

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.