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

  • Home
  • SEARCH
  • 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 6369959
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:52:11+00:00 2026-05-25T00:52:11+00:00

I’m using sockets to communicate between a server and client. For some reason though,

  • 0

I’m using sockets to communicate between a server and client.
For some reason though, the client skips every second line that the server has sent.

Client’s code:

    ...

    out.println(console.readLine());                //Client initiates (sent to server)

    while ((userOut = in.readLine()) != null)       //Waits for response
    {
        System.out.println("Server says: " + userOut);  //Prints response

        userIn = console.readLine();                //Gets user input
        out.println(userIn);                        //Sends user input to server
    }

    ...

Servers Code:

    ...

    while ((clientIn = in.readLine()) != null)  //Waits for clients message
    {
        System.out.println("Client says: " + clientIn); //Print clients message

        //Send appropriate response
        if (clientIn.equals(CLIENT_INSTRUCTION_LOGCALC))
        {
            out.println(SERVER_RESPONSE_LOGCALC_OK); //Send response to client
            System.out.println("Message sent: " + SERVER_RESPONSE_LOGCALC_OK); //Print response sent
        }

        else if (clientIn.equals(CLIENT_INSTRUCTION_SB))
        {
            out.println(SERVER_RESPONSE_SB_CHANGE);
        }

        else if (clientIn.equals(CLIENT_INSTRUCTION_BYE))
        {
            out.println(SERVER_RESPONSE_BYE_OK);
        }

        else if (clientIn.equals(CLIENT_INSTRUCTION_END))
        {
            out.println(SERVER_RESPONSE_END_OK);
        }

        else
        {
            out.println(SERVER_RESPONSE_INPUT_ERR);
        }
        ...

An example of using this displays (client first):

 LOGCALC
 Server says: LOGCALC: OK
 LOGCALC
 Server says: 

Server:

Client says: LOGCALC
Message sent: LOGCALC: OK

Client says: LOGCALC
Message sent: LOGCALC: OK

Hopefully you can see that in the second LOGCALC message sent to the server, the server responded, but the client did not receive the servers response.

Any thoughts?

  • 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-05-25T00:52:13+00:00Added an answer on May 25, 2026 at 12:52 am

    Looking at your output, it appears that you have an extra linebreak in SERVER_RESPONSE_LOGCALC_OK, since System.out.println("Message sent: " + SERVER_RESPONSE_LOGCALC_OK); has an extra line after it in the server output. I’d remove the extra newline or use a simple out.print(SERVER_RESPONSE_LOGCALC_OK) instead of out.println(SERVER_RESPONSE_LOGCALC_OK);. This should solve your skipping problem.

    The underlying flaw you’re experiencing is because you only read one line at a time and then wait for user input before reading another line instead of as many lines as are available before waiting for user input. I’m betting that if you do something like the code below in the client you will see different output.

    out.println(console.readLine());                //Client initiates (sent to server)
    
        while ((userOut = in.readLine()) != null)       //Waits for response
        {
            System.out.println("Server says: " + userOut);  //Prints response
    
            if(!in.available()){
              userIn = console.readLine();                //Gets user input
              out.println(userIn);                        //Sends user input to server
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I've got a string that has curly quotes in it. I'd like to replace
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I have a French site that I want to parse, but am running into
I'm making a simple page using Google Maps API 3. My first. One marker

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.