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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T05:47:15+00:00 2026-06-16T05:47:15+00:00

I am creating a simple chat program using Java SE 7 via ServerSocket/Socket. I

  • 0

I am creating a simple chat program using Java SE 7 via ServerSocket/Socket. I was wondering if it is possible to have a mismatch of data inside the sent model/entity from client to server or vise-versa? I am getting a mismatch of data from the sent model of my client to its server when I sent the same class type with different containing data consequently.

Example
Client: Sending...  ID: 3
Server: Received... ID: 3
Client: Sending...  ID: 4
Server: Recieved... ID: 3

Here my generic paradigm of my model/entity:

abstract class Record<T> extends Observable implements Serializable {
   // with generated "serialVersionUID" by the EclipseIDE[Juno]
   protected int id;
   // Constructor, Getters/Setters, Abstract methods
   // hashCode(): Generated by Eclipse
   // equals(): Generated by Eclipse, replacing Record with Record<T>
}
abstract class RecordVersion<T> extends Record<T> implements Serializable {
   // with generated "serialVersionUID" by the EclipseIDE[Juno]
   protected int version;
   // Constructor, Getters/Setters, Abstract methods
   // hashCode(): Generated by Eclipse
   // equals(): Generated by Eclipse, replacing RecordVersion with RecordVersion<T>
}
class SampleRecord extends RecordVersion<SampleRecord> {
   // with generated "serialVersionUID" by the EclipseIDE[Juno]
   private String data;
   // Constructor, Getters/Setters, Abstracted methods
   // hashCode(): Generated by Eclipse
   // equals(): Generated by Eclipse
}

Any ideas how to solve this? Thanks.

UPDATE 1:

Reading the socket.getInputStream() via java.io.ObjectInputStream

class ReadRunnable implements Runnable {
  private Object lastObjectReceived = new Object();
  @Override
  public void run() {
    while(true) {
       try {
         // inStream: java.io.ObjectInputStream
         Object objectReceived = inStream.readObject();       
         if(objectReceived .equals(lastObjectReceived ))
           objectReceived = inStream.readObject();
         else
           lastObjectReceived = objectReceived;
       } catch(Exception e) {
         ex.printStackTrace();
       }
    }
  }
}
  • 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-16T05:47:17+00:00Added an answer on June 16, 2026 at 5:47 am

    If you are attempting to send the same object instance multiple times over the same ObjectOutputStream, you are going to run into problems because Object streams preserve object identity. in order to resend the same object instance with new data, you need to call ObjectOutputStream.reset() in between.

    Also, in your loop you are “losing” one of the objects sent. the first branch of your if block calls .readObject(), and then the beginning of your while loop calls .readObject() again, discarding the result of the previous call before comparing it.

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

Sidebar

Related Questions

I'm creating a very simple Java chat program, using the Java TCP sockets. I'm
I have made a program in Flex for creating simple schedules, similar to MS
I have seen several methods for creating simple fixed width single column layout using
I am creating a simple chat program where clients can send messages to a
I'm creating a simple chat app. Have installed nginx on Ubuntu 11.10, with PHP
I am creating simple app on Silverlight 4. In folder of View I have
Creating a simple RPG game, first time using XNA. Trying to get my character
I am creating a simple blog applicaton. I have to add comments to a
I'm creating a simple program with the possibility to change the language and I
I am thinking of a simple chat application in Window Phone using Microsoft Push

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.