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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T05:04:03+00:00 2026-06-10T05:04:03+00:00

I have a Java Client/Server chat application and after a connection gets established, only

  • 0

I have a Java Client/Server chat application and after a connection gets established, only about 1 quarter of the data is being received by the recipient. What could the problem be? Here is a print screen of what happens exactly:
Printscreen of Application

Code for reading from socket:

public void somethingElse(){
    try {
           if(in.readLine() != null){
                messageBufferIn = in.readLine();
               System.out.println(in.readLine());
               chat.append(recipient + ": " + messageBufferIn + "\n");
           }
           } catch (IOException e) {
            e.printStackTrace();
          }     
}

Code for thread that runs above method:

public class chatListener extends Thread{
static main main = new main();
//static Thread mainThread = new Thread(main);
public void run(){
    while(main.isConnected == true){
        main.somethingElse();
    }
}

}

The above thread gets run as soon as a connection gets established

Thanks for any help

  • 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-10T05:04:05+00:00Added an answer on June 10, 2026 at 5:04 am

    Each time you call in.readLine, the scanner moves down to the next line; you can’t keep calling it a few times, as it will skip the lines you never used essentially. Try this to replace somethingElse():

    public void somethingElse(){
        try {
               String line;//Added a variable to store the current line to; readLine is 
               //dynamic, it returns the next line each call, so if we store to a variable,
               //we only call it once, and hold that value
               if((line = in.readLine()) != null){// (line = in.readLine()) != null is shorthand to store readLine to line, and then check if that returned value is null or not
                   System.out.println(line);//Print out the line
                   chat.append(recipient + ": " + line + "\n");//Append it
               }
         } catch (IOException e) {
            e.printStackTrace();
         }     
    }
    

    Before, you were calling in.readLine once to check if it was null, then you saved the next line, then printed the next one. Hence the pattern of (fail success fail | fail success fail etc.) = Only messages 2 + 5 showing up

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

Sidebar

Related Questions

I have developed a java swing client-server application. The server has many services like
Background: I have written a java swing based client server application. The server is
I have developed a basic Chat application in Java. It consists of a server
i have a java chat server & client, that works fine. I made a
I have a Java client - server application. The client is designed to run
we have a java server-client application with an applet in the client side. our
I have a Client/ server application where the Server is in java and Client
I have written a java client server application (not http), which i need to
I have a Java program that mirrors a connection from a client server to
I'm trying to write a simple client/server chat application in 2 languages - Java

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.