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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T09:55:11+00:00 2026-05-18T09:55:11+00:00

I’ve been trying to debug this for 2 hours and i just can’t explain

  • 0

I’ve been trying to debug this for 2 hours and i just can’t explain it.
I have a server and a client. (server manages some Auctions).

What happens:

  1. The client request something , server sends data back and client receives it just fine.

  2. The client sends something to the server, and the server updates some data.

  3. The client makes the same request as first time (1.), the server send back the updated
    data, but the client does not receive the new update data, instead it receives the old data (as it got it in the first request (1.).

The data that is being sent is just a Java Bean with two List-s.
And the code:

 // CLIENT CLASS
// creates socket, sends and listens on the socket
// listening is done on a separate thread
public class ServerConnector {

private Socket socket = null;
private ObjectOutputStream out = null;
private Display display;
private ServerListener listener;
public ServerConnector(Display display) {
    this.display = display;
        try {
            socket = new Socket("localhost",33333);
            out = new ObjectOutputStream(socket.getOutputStream());
        } catch (UnknownHostException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        listener = new ServerListener(socket, display);
        new Thread(listener).start();


}



public void sendRequest(Request request) {
    try {
        out.writeObject(request);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}

class ServerListener implements Runnable {
    private Socket socket;
    private ObjectInputStream in = null;
    private Display display;
    public ServerListener(Socket socket,Display display) {
        this.socket = socket;
        this.display = display;
        try {
            in = new ObjectInputStream(socket.getInputStream());
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    @Override
    public void run() {
        Response response =null;

        try {
            while ((response = (Response)in.readObject()) != null) {
                if (response.getCars().size() > 0) {
                    display.showAvailableCars(response.getCars());
                }
                if(response.getAucs().size() > 0) {
                    List<Auction> auctionz  = response.getAucs();//HERE 1st time it gets the GOOD data, 2nd time should get UPDATED DATA but instead receives the OLD DATA (same as 1st time).
                    display.showOpenAuctions(auctionz);
                }
                response = null;
            }
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    }

}

}
//CLIENT CLASS
// controls when something should be sent, and print out responses
public class Display {
Scanner console = new Scanner(System.in);
ServerConnector server = new ServerConnector(this);
List<Car> cars;
List<Auction> aucs;

public void show() {
    int opt = 0;
        System.out.println("1. Show available cars for auction.");
        System.out.println("2. Show open auctions.");
        opt = console.nextInt();
        Request request = new Request();
        if (opt == 1)
            request.setRequest(Request.GET_CARS);
        if (opt == 2) {
            request.setRequest(Request.GET_OPEN_AUCTIONS);
        }
        server.sendRequest(request);

    }


public void showAvailableCars(List<Car> cars) {
    int i = 0;
    for (Car c : cars ){
        i++;
        System.out.println(i +". " + c.getMaker() + " " + c.getModel() + " price: " + c.getPrice());
    }
    System.out.println("Select car to open Auction for:");
    int selectedCar = console.nextInt();
    if (selectedCar != 0) {
        if (selectedCar <= cars.size()) {
            Request request= new Request();
            request.setRequest(Request.OPEN_AUCTION);
            Car c = cars.get(selectedCar-1);
            request.setCar(c);
            server.sendRequest(request);
        }
    }
    show();
}


public void setCars(List<Car> cars) {
    this.cars = cars;

}


public void showOpenAuctions(List<Auction> aucs2) {
    int i = 0;
    for (Auction auc : aucs2) {
        i++;
        System.out.println(i+ ". " + auc.getCar().getModel() + " " + auc.getCar().getMaker() + " last price: " + auc.getPrice());
    }
    System.out.println("You can now make offers");
    System.out.println("Input auction number:");
    int selectedAuction = 0;
    selectedAuction = console.nextInt();
    if (selectedAuction > 0 && selectedAuction <= aucs2.size()) {
        System.out.println("Offer new price:");
        int price = console.nextInt();
        Request request= new Request();
        request.setRequest(Request.MAKE_OFFER);
        request.setAuctionId(aucs2.get(selectedAuction-1).getId());
        request.setPrice(price);
        server.sendRequest(request);
    }
    show();

}


public void setOpenAuctions(List<Auction> aucs2) {
    this.aucs = aucs2;

}

}
// SERVER CLASS : send and receives
public class ClientManager implements Runnable {

private AuctionManager manager = new AuctionManagerImpl();
private Socket client;
private ObjectInputStream in = null;
private ObjectOutputStream out = null;


public ClientManager(Socket socket) {
    this.client = socket;
     try {
          in = new ObjectInputStream(client.getInputStream());
          out = new ObjectOutputStream(client.getOutputStream());
     } catch(Exception e1) {
             try {
                 e1.printStackTrace();
                client.close();
       }catch(Exception e) {
               System.out.println(e.getMessage());
             }
             return;
         }
}

@Override
public void run() {
    Request req = null;
    try {
            while ((req = (Request)in.readObject()) != null) {
                if (req.getRequest() != null) {
                    if (req.getRequest().equals(Request.GET_CARS)) {
                        Response response = new Response();
                        response.setCars(manager.getAvailableCars());
                        out.writeObject(response);
                        continue;
                    }

                    if (req.getRequest().equals(Request.OPEN_AUCTION)) {
                        manager.openAuction(req.getCar());
                        continue;
                    }

                    if (req.getRequest().equals(Request.GET_OPEN_AUCTIONS)) {
                        Response response = new Response();
                        response.setAucs(manager.getHoldedAuctions()); //this line ALWAYS sends to the client GOOD, UPDATED DATA

                        out.writeObject(response);
                        out.flush();
                        continue;
                    }
                    if (req.getRequest().equals(Request.MAKE_OFFER)) {
                        Auction auction = manager.getOpenAuction(req.getAuctionId());
                        manager.updateAuction(auction, req.getPrice(),client.getRemoteSocketAddress().toString());
                        continue;
                    }
            }
        }
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (ClassNotFoundException e) {
        // TODO Auto-generated catch block
        e.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-05-18T09:55:11+00:00Added an answer on May 18, 2026 at 9:55 am

    It could be because you are using ObjectOutputStreams. Remember that ObjectOutputStreams will cache all objects written to them so that if the same object is written again in the future it can write a back-reference instead of re-writing the whole object. This is necessary when writing an Object graph.

    Your code fragment:

    if (req.getRequest().equals(Request.GET_CARS)) {
        Response response = new Response();
        response.setCars(manager.getAvailableCars());
        out.writeObject(response);
        continue;
    }
    

    is writing the object returned by manager.getAvailableCars(). The next time a request is received the same object (but now with different contents) is written – but the ObjectOutputStream doesn’t know about the new contents so it just writes a back-reference. The ObjectInputStream at the other end sees the back-reference and returns the same object it read last time, i.e. the original data.

    You can fix this by calling ObjectOutputStream.reset() after each response. This will clear the stream’s cache.

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

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have some data like this: 1 2 3 4 5 9 2 6
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
Does anyone know how can I replace this 2 symbol below from the string

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.