Socket Object Serialization StreamCorruptionException

Hi,
I'm currently attempting to send objects across the network via serialization. I can send Strings back and forth from client to server and server to client without a problem, but when i try to send and recieve a different object (one i wrote) i get EOFException or StreamCorruptionException. This was working before i added a considerable amout to the code. I just don't understand why it breaks now. Any help would be greatly appreciated. And i apologize in advance for leaving all of my print statements in.
public class ServerThread extends Thread {
     private Socket socket = null;
     private Buyer buyer = null;
     private Bid bid = null;
     private Auctioneer auctioneer = null;
     private int clientId;
     private String userInfo[] = new String[2];
     private static final String REQUEST_NAME = "1";
     private static final String SUCCESS = "SUCCESS";
     private static final String FAIL = "FAIL";
    private static ObjectOutputStream out = null;
    private static ObjectInputStream in = null;
     public ServerThread(Socket socket, Auctioneer auctioneer, int clientId) throws SocketException{
          super("ServerListenerThread");
          this.socket = socket;
          this.auctioneer = auctioneer;
          this.clientId = clientId;
          this.setPriority( 10 );
     public boolean userExists(String name){
          for (Iterator it = auctioneer.getBuyers().iterator(); it.hasNext();){
               buyer = (Buyer)it.next();
               if(buyer.getName().equals( userInfo[0])) return true;
          return false;
     public void run(){
          try {
               in = new ObjectInputStream(socket.getInputStream());
               out = new ObjectOutputStream(socket.getOutputStream());
               Integer cid = new Integer(clientId);
               bid = null;
               buyer = null;
               String msg = null;
               try{
                    // listen for login: user/password
                    msg = (String)in.readObject();
                    userInfo[0] = msg.substring(0,msg.indexOf(","));
                    userInfo[1] = msg.substring(msg.indexOf(",") + 1, msg.length());
                    if(userExists(userInfo[0])){
                         System.out.println("wes already logged in");
                         out.writeObject(FAIL);
                         return;
                    else
                         System.out.println("wes not logged in");
                         out.writeObject(SUCCESS);
                    out.writeObject(cid);
                    out.flush();
                    buyer = (Buyer)in.readObject();
                    auctioneer.addBuyer( buyer);
               int n = 0;
               while ((bid = (Bid)in.readObject()) != null && !auctioneer.exit){
                    auctioneer.addBid(bid);
                    n++;
                    System.out.println("this was bid: " + bid.getBidAmt() + " this many times " + n);
               }catch(SocketException e){
                    System.out.println("Client " + clientId + " Disconnected!!!");
                    //controller.notifyLostClient(buyer);
                    auctioneer.removeBuyer( buyer);
                    auctioneer.update();
          } catch (IOException e) {
               // TODO Auto-generated catch block
               e.printStackTrace();
          } catch (ClassNotFoundException e) {
               // TODO Auto-generated catch block
               e.printStackTrace();}
Client Side
public boolean connect(){
          boolean connect = false;
          System.out.println("trying to connect...");
               for(int i = 0; i <=9; i++){
                    System.out.println("trying to connect...");
                    try {
                         socket = new Socket(ip, PORT);
                         socket.setTcpNoDelay( true );
                         System.out.println("this doesn't take long");
                         out = new ObjectOutputStream(socket.getOutputStream());
                         in = new ObjectInputStream(socket.getInputStream());
                         connect = true;
                         break;
                    }catch(UnknownHostException e){
                         System.out.println("No Server At: " + ip[i].getHostAddress() );
                    }catch(IOException e){
                         System.out.println("No Server At: " + ip[i].getHostAddress() );
               if(connect){
                    return true;
               else{
                    int i = JOptionPane.showConfirmDialog(null,
                              " Couldn't find " + HOST + "\n Try Again?"
                              , "WARNING", JOptionPane.YES_NO_OPTION,
                              JOptionPane.QUESTION_MESSAGE);
                    if (i == 1)
                         System.exit(1);
                    else {
                         return false;
               return false;
     public boolean login(){
          try {
               try {
                    String msg = USER + "," + PASSWORD;
                    out.writeObject( msg );
                    out.flush();
                    msg = (String)in.readObject();
                    System.out.println(msg);
                    if(msg.equals("SUCCESS")){
                         clientId = (Integer)in.readObject();
                         System.out.println("Client " + clientId.toString() );
                         msg = "TEST";
                         out.writeObject( msg );
                         out.flush();
                         Bid newBid = new Bid(buyer, 12);
                         out.writeObject(newBid);
                         out.flush();
                         buyer = new Buyer(USER,clientId,socket.getLocalAddress().getHostName());
                         out.writeObject(buyer);
                         out.flush();
                         Object obj = in.readObject();
                    else{
                         int i = JOptionPane.showConfirmDialog(null,
                                   " System could not log you in\n Try Again?"
                                   , "WARNING", JOptionPane.YES_NO_OPTION,
                                   JOptionPane.QUESTION_MESSAGE);
                         if (i == 1)
                              System.exit(1);
                         else
                              return false;
               } catch (ClassNotFoundException e1) {
                    e1.printStackTrace();
          } catch (IOException e2) {
               e2.printStackTrace();
          new ClientListenerThread(controller).start();
          return true;
Any Ideas???

I fogot to give the code of the objects im sending across
package taxsale.shared;
import java.io.Serializable;
* Created on May 27, 2005
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
* @author Admin
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
public class Bid implements Serializable{
     private int bidAmt;
     private Buyer buyer;
     private String time;
     public Bid(){
          this.buyer = new Buyer("", new Integer(0), "");
          this.bidAmt = 19;
     public Bid(Buyer buyer, int bidAmt){
          this.buyer = buyer;
          this.bidAmt = bidAmt;
      * @return Returns the bidAmt.
     public int getBidAmt() {
          return bidAmt;
      * @return Returns the buyer.
     public Buyer getBuyer() {
          return buyer;
     public void setTime(String time){
          this.time = time;
     public String getTime(){
          return time;
package taxsale.shared;
import java.io.Serializable;
* Created on May 26, 2005
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
* @author Admin
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
public class Buyer implements Serializable{
     private String name;
     private Integer id;
     private Boolean connected;
     private String cName;
     public Buyer(){
     public Buyer(String name, Integer id, String cName){
          this.name = name;
          this.id = id;
          this.cName = cName;
          this.connected = new Boolean(false);
      * @return Returns the id.
     public Integer getId() {
          return id;
      * @param clientId
     public void setId(Integer clientId) {
          id = clientId;
      * @return Returns the cName.
     public String getCName() {
          return cName;
      * @param name The cName to set.
     public void setCName(String name) {
          cName = name;
      * @return Returns the user.
     public String getName() {
          return name;
      * @param user The user to set.
     public void setName(String name) {
          this.name = name;
}Thanks

Similar Messages

  • Customizing Forte object serialization

    Forte supports serialization of arbitrary object graphs into streams.
    However, there do not seem to be any well documented ways to customize
    this serialization, e.g. by using a different encoding scheme. It would
    seem there must be some support in there somewhere. I suppose at the
    very least, one could parse a serialized object (once one decoded the
    Forte encoding scheme) and do the conversion from that. That seems
    suboptimal, though.
    Has anyone done this? Any thoughts on how it might be done?
    Regards,
    Coty
    To unsubscribe, email '[email protected]' with
    'unsubscribe forte-users' as the body of the message.
    Searchable thread archive <URL:http://pinehurst.sageit.com/listarchive/forte>

    JavaFunda wrote:
    Object serialization is the process of saving an object's state to a sequence of bytes. Does it saves only the instance variable or also the object methods(like getter and setter methods) ? Only the state--the instance variables. It doesn't save the class definition. That has to be available separately (via classloader) at deserilaization time. In other words, you cannot deserialize an instance of a class that is not on your classpath.
    Once we we write the object to outputstream or some text file, how does it get transmitted over network?The same way any other bytes get transmitted. You have a Socket. You get its OutputStream. You wrap that in an ObjectOutputStream. When you write to the ObjectOutputStream, that writes through to the Socket's OutputStream, which is responsible for putting the bytes on the wire.
    Does we write the java object to text file only duuring serialization?We write the objects to wherever the other end of the ObjectOutputStream is connected to. Just like any other I/O.

  • How to create HTTPS or secure Socket objects in JDK 1.4?

    I would like to see sample working code that shows creation
    of Sockets objects that work with HTTPS using JDK 1.4. I am doing
    a POST operation (form submission) on HTTPS URL. I must use Socket
    objects and cannot use URLConnection (I know URLConnection solves the problem automatically in JDK 1.4).
    Also sample code for POST operation would be appreciated.

    I wrote this a little while ago to test out Secure Sockets in 1.4. I assume you are doing the client since you are trying talk to a website or something like that, anyway this test class is tested and works, but you will have to clean it up.
    Pup
    import java.io.*;
    import java.security.*;
    import javax.net.ssl.*;
    public class HelloClientSSL {
        public static void main(String[] args) {
            try {
                int port = 8005;
                int tempport =0;
                if(args.length > 1) {
                    try {
                        tempport = Integer.parseInt(args[1]);
                        port = tempport;
                    catch (Exception e) {
                        System.out.println("Sorry this is not a valid number " + args[1]);
                        System.out.println("Using Default port 8005");
                Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());           
                SSLSocketFactory sslFact = (SSLSocketFactory)SSLSocketFactory.getDefault();
                SSLSocket s = (SSLSocket)sslFact.createSocket(args.length == 0 ? "127.0.0.1" : args[0], port);
                s.setEnabledCipherSuites(s.getSupportedCipherSuites());
                java.net.Socket n = (java.net.Socket) s;
                java.io.ObjectOutputStream OOS = new java.io.ObjectOutputStream(n.getOutputStream());
                BufferedReader in = new BufferedReader (new InputStreamReader(n.getInputStream()));
                String response = "";
                String temp = "This is reall cool and stuff\n";
                OOS.writeObject(temp);
                OOS.writeObject("Hello\n");
                while((response =in.readLine()) != null){
                    System.out.println("Socket message: " + response);
                in.close();
            } catch (Exception e) {
                System.out.println("Exception" + e);
                e.printStackTrace();
    }

  • HTTPS support in socket object?

    Is there any support for HTTPS requests in the socket object? I know there is a BUNCH of data encryption that needs to go on and I'm not sure if indesign has anything built in to do so.

    Allan wrote:
    graysky wrote: Maybe Allan can do it in his spare time
    no need...  falconindy has already coded a switch from libfetch to libcurl.  https support will be there once that is finished.
    Oh man those pacman devs are so cool they just add features even if you don't want too 

  • [b]How to convert a Socket object in a C socket file descriptor[/b]

    Hi all,
    I need to make a getsockopt() call using JNI, but I don't know how to convert a Java Socket object in the integer corresponding to the socket file descriptor.
    Thank you in advance!
    Fernando

    I was wrong in my previous post. FileDescriptor is used for PlainSocketImpl. This means I can give you a solution.
    The solution does involve rebuilding some built-in Java classes to make certain fields accessible.
    You have to modify access to three classes:
    1. You can either use my SocketGetImpl or just rebuild java.net.Socket and change from
    SocketImpl getImpl() throws SocketException {
    to
    public SocketImpl getImpl() throws SocketException {
    2. In java.net.SocketImpl change from
    protected FileDescriptor getFileDescriptor() {
    to
    public FileDescriptor getFileDescriptor() {
    3. In java.io.FileDescriptor I would add the method
    public int getFd(){ return fd; }
    Then my test program becomes:
    package myhack;
    import java.io.*;
    import java.net.*;
    public class DoSock {
            public static void main(String args[]) throws Exception{
                    Socket s= new Socket("mywebserver",80);
                    System.out.println("s="+s);
                    SocketImpl si = SocketGetImpl.getImpl(s);
                    System.out.println("si="+si);
                    FileDescriptor fd = si.getFileDescriptor();
                    System.out.println("fd="+fd);
                    System.out.println("fd int="+fd.getFd());
    }And you still have to invoke as:
    java -Xbootclasspath/p:. myhack.DoSock
    or boot path pointing at jar file, etc.

  • InDesign CS4 / CS5 missing JavaScript Socket() object?

    If I do
    var mySocketObject = new Socket();
    socket.open("mywebsite.com:80", "BINARY")
    in Photoshop, it creates a socket object called mySocketObject, which is not null and opens the socket correctly.
    If I do the same thing in InDesign CS5, the same command fails.
    I know this works in InDesign CS3, so what does one need to do to make Socket() work in InDesign CS4/5?

    Adobe's own Javascript Tools Guide is your friend for snippets like these.
    This is from the CS4 guide, but it should work for CS5 as well:
    reply = "";
    conn = new Socket; // access Adobe’s home page
    if (conn.open ("www.adobe.com:80"))
    // send a HTTP GET request
    conn.write ("GET /index.html HTTP/1.0\n\n");
    // and read the server’s reply
    reply = conn.read(999999);
    conn.close();

  • 2D objects Serialization problem

    Welcome!
    I'm making a net game using RMI and I have this problem.
    When I'm trying to join my client with the server an error occures:
    Error: error marshalling arguments; nested exception is:
         java.io.NotSerializableException: java.awt.geom.Ellipse2D$Double
    My client contains an Object extending a JPanel class. There are 2D object used to make the map, and that's why this error occures.
    It's a funny thing, cause I'm not sending a whole Object of my client, but only it's refference (using "this" in the join() method) so I dont know why does the 2D object need to be serialized and sent :|?
    Any way, my question is how to make 2D objects serializable!? I have jdk1.5.0_06 and as far as I remember they should be srializable in this version. Mabey I'm dooing something wrong!? Mabey it's nessesary to ad an appropreate code-line or import sth... i don't know
    please help me... I have little time to finish my project, and this thing is blocking my work.
    Big thanks to anybodey who will help.
    regards floW

    I'll tel u the whole story then, my problem is as follows:
    public class BounceThread{
       public static void main(String[] args)   {
          JFrame ramka = new BounceFrame();
             ramka.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
             ramka.setVisible(true);
    class BounceFrame extends JFrame{
    public BounceFrame()
          setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);
          setTitle("MiniGolf v 1.0");
          panel = new BallPanel(); // this contains maps made with 2D objects
          panel.setBackground(Color.green);
          panel.setVisible(panel.czy_wida&#263;_panel());
          add(panel, BorderLayout.CENTER);
    // I add a menu bar, that starts a net game:
    JMenuBar pasekMenu = new JMenuBar();
              setJMenuBar(pasekMenu);
              JMenu menuGra = new JMenu("Game");
           // and so on... and finaly I add an option:
              menuGame_Nowa.add(new
                        AbstractAction("Net game")
                             public void actionPerformed(ActionEvent event)
                                  net_game(panel);
    // here i write my net_game method:
    public void net_game(BallPanel aPanel)
         //here, i make an Client object, and connect him with my server
         client = new mgClient(panel);
         client.join();
         // I give panel as a paramete, cause I cant think of another way of leting my server to uce it's (panels) methods
         // If I join only a name of my client, then how can I change the panel in my BounceFrame from the Clients method
         // "shouted" by the server!? It has to be a field in the client's object.
         // Is there any other way out!?
    // Class BouceFrame holds the panel as a field:
    private mgClient client;
    private BallPanel panel;
    //and so on...
    }and that's the real problem I'm facing here. Is there any solution!? I think, that making a Client's field out of my panel is the only way ot. And that means I need those 2D objects serialized... :(
    Please help if u can.
    Regards floW

  • Servlet and Object Serialization

    Hi,
    I am developing a routing server in Java
    2 Instances of the same server will be running in 2 different data centers.
    The servers have a Jetty server embedded with a Servlet inside.
    Server 1 will use a GET method to talk to the Server 2 -> Servlet which will write the state of an object back which will read by Server 1 and reconstruct the object back.
    Do you find any issues in Object Serialization/DeSerialization in the Servlet.
    What are the factors that I need to consider in this case?
    Regards,
    Jana

    Make sure that your servlet handles the transaction in the same thread that doPost() or doGet() is called in.
    I ended up porting some old ServerSocket based code to a servlet, and was handing off the request and response objects to a handler thread on the server side. I ended up with a ton of intermittent errors like this.
    Once I started handling the transactions in the same thread things worked heartbreakingly well.

  • Trouble getting the socket object to work

    I'm trying to pull an external XML file into InDesign, so I know I need to use the Socket object. I went to the documentation and copied/pasted the code from there:
    reply = "";
    conn = new Socket;
    // access Adobe’s home page
    if (conn.open ("www.adobe.com:80")) {
    // send a HTTP GET request
    conn.write ("GET /index.html HTTP/1.0\n\n");
    // and read the server’s reply
    reply = conn.read(999999);
    conn.close();
    When I ran it, I received this error message:
    So, I'm stuck! Either Adobe's code sample has an error, or, more likely, there's something wrong on my end. If I had to guess, I'd guess that it's some kind of proxy problem, but I don't know for sure and don't know how to find out.
    Can anyone help? The principles of the Socket object make sense to me, but if I can't get even the sample to work, I don't really have anywhere to go with this.

    i know that's not the swf object. But I tried to use that
    little tutorial and it isn't like one size fits all. The previous
    code i used had a bunch of parameters that are not present in this
    swf object thing.
    Any advice would be great.

  • Runtime Object serialization

    Hi,
    Could someone explain the concept of Runtime Object Serialization with a simple example?
    Thanks

    import java.io.*;
    /* you NEED to make the class implement Serializable */
    class Client implements Serializable {
        private String name;
        private String address;
        public String getName() { return name; }
        public String getAddress() { return address; }
        public void setName(String name) { this.name = name; }
        public void setAddress(String address) { this.address = address; }
        public String toString() { return "name='" + name + "' and address= " + address + "'"; }
    public class Test17 {
        public static void main(String[] args)  throws Exception {
            ObjectOutputStream oos = new ObjectOutputStream (new FileOutputStream ("test.bin"));
            Client myClient = new Client();
            myClient.setName("Steve Jobs");
            myClient.setAddress("1 Infinite Loop; Cupertino, CA 95014");
            System.out.println (myClient);
            oos.writeObject (myClient);
            oos.close();
            ObjectInputStream ois = new ObjectInputStream (new FileInputStream ("test.bin"));
            Client yourClient = (Client) ois.readObject();
            System.out.println (yourClient);
    }Run the program above. It creates an object of the class "Client", serializes it into a file named "test.bin" and recreates the object reading it from the same file.
    Dumping the binary file you get this:
    0000    AC ED 00 05 73 72 00 06  43 6C 69 65 6E 74 F1 D7   ....sr..Client..
    0010    74 76 C4 64 FD 43 02 00  02 4C 00 07 61 64 64 72   tv.d.C...L..addr
    0020    65 73 73 74 00 12 4C 6A  61 76 61 2F 6C 61 6E 67   esst..Ljava/lang
    0030    2F 53 74 72 69 6E 67 3B  4C 00 04 6E 61 6D 65 71   /String;L..nameq
    0040    00 7E 00 01 78 70 74 00  24 31 20 49 6E 66 69 6E   .~..xpt.$1 Infin
    0050    69 74 65 20 4C 6F 6F 70  3B 20 43 75 70 65 72 74   ite Loop; Cupert
    0060    69 6E 6F 2C 20 43 41 20  39 35 30 31 34 74 00 0A   ino, CA 95014t..
    0070    53 74 65 76 65 20 4A 6F  62 73                     Steve JobsYou can see a lot of things in the serialization of the object Client - the name of the class is written, the names of the fields, the type (java/lang/String), and the values of the fields as UTF-8 encoded strings.

  • Object serializable?

    Hi,
    When writing a vector of my own objects out to a file, do the objects need to be serializable even though it is actually the vector I am outputting?
    Also, each of my objects in this vector have a field that is a vector of other objects...do I need to declare those objects serializable also?

    I think you still need to implement serializable on objects contained in the vector. I tried serializing a hashmap and my hashmap contained objects which needed to be serialized before the hashmap could be stored in a file.

  • SetAttribute() makes object serializable Recursively ?

              Hi everyone,
              could anyone answer me whether httpSession.setAttribute(key, very big object)
              makes the object serializable recursively.
              What I mean is, I am storing an object bigObject in http session using setAttribute().
              This bigObject contains several other objects which are not serialized.
              But I have read that setAttribute() makes the object serializable.
              So, does it mean that all the objects stored in bigObject also will be serialized
              thanks,
              jyothi
              

    But you can't serialize an Object that isn't Serializable somewhere in it's
              inheritance. A method can't make an Object Serializable.
              "jyothi" <[email protected]> wrote in message
              news:[email protected]...
              >
              > But i read clearly some where in bea online manual that use
              setAttribute() which
              > makes the object searializable. So I wonder whether this
              setAttribute() does
              > the searlization recursively ?
              >
              > thanks,
              > jyothi
              >
              > "justin" <[email protected]> wrote:
              > >
              > >Cluster requirement is that all objects placed in a session should be
              > >serializable.
              > >So your Big objects with small object which are not serializable is going
              > >to be
              > >a problem.
              > >
              > >"jyothi" <[email protected]> wrote:
              > >>
              > >>Hi everyone,
              > >>
              > >>could anyone answer me whether httpSession.setAttribute(key, very
              > >>big object)
              > >> makes the object serializable recursively.
              > >>
              > >>What I mean is, I am storing an object bigObject in http session using
              > >> setAttribute().
              > >> This bigObject contains several other objects which are not serialized.
              > >>
              > >>But I have read that setAttribute() makes the object serializable.
              > >>
              > >>So, does it mean that all the objects stored in bigObject also will
              > >>be serialized
              > >>?
              > >>
              > >>thanks,
              > >>jyothi
              > >
              >
              

  • Object serialization failure during OutOfMemory error (EOFException)

    Hello all,
    We are seeing a very strange situation when writing a serializable object to a flat file, specifically during an OutOfMemory condition. Our application saves the state of an object if an error occurs, and retries at a later point by reviving the object from its serialized form. We recently encountered a series of EOFExcetions when trying to reload the serialized object. Looking at the serialized data, we see that the file is indeed incomplete, and that it appears to be the serialized representation of the data contained within the object that is missing (the structure of the object appears to be stored in the serialized file, but not the runtime data).
    The code that produces and consumes these serialized objects is used in a variety of locations, and even in the case where these EOF errors occurred usually works as expected. The difference appears to be that the error condition which lead to the object serialization was in-fact an OutOfMemory error. That is, we had an OOM error elsewhere in our application, which caused our objects to be serialized to disk. During this serialization process we end up with corrupt (incomplete) serialization data.
    So.. the question is: Is it possible that the OutOfMemory situation causes the JVM to incorrectly serialize an object (without an error), and specifically to omit runtime data (variables) from the serialized form of the object?
    Thanks/

    jasonpolites wrote:
    So.. the question is: Is it possible that the OutOfMemory situation causes the JVM to incorrectly serialize an object (without an error), and specifically to omit runtime data (variables) from the serialized form of the object?you're sure that the serialization process completed without an error? how do you know the the OOME did not cause the serialization to fail (because the serialization process itself will require more memory, hence if it is happening while the system is near the memory peak, it is likely to fail as well)? generally, when a jvm starts throwing OOME's all bets are off. failures in random places can easily cause the whole internal state of a system to become invalid.

  • Object serialization EOFException

    Essentially what I want to do is write to an object to a file. The program can terminate and then when I start the program again, it will read the object from the file and restore the program's original state before it was terminated.
    I get an EOFException with this code
    //insert code that gets input which will be stored in a hashtable
    //save Hashtable in "data.dat" using ObjectOutputStream
    //program terminates
    //program is re-ran again and checks for existing file
    File f = new File("data.dat");
    if(f.exists()){
           ObjectInputStream ois = new ObjectInputStream(new FileInputStream(f));
           Object obj = ois.readObject(); //EOF exception occurs here
    }I know the above code works if I write the Hashtable and then read it back immediately without terminating in between. Am I missing something? Can object serialization be used in such a way that I can restore a program's original state before it was terminated?

    Sorry, I led you to believe that the actual class itself was going to be written to a file. I meant to say that the Hashtable in the class should be written to a file and then later on when I start the program again, it will restore the Hashtable to it's original state.
    My writing coding is something like this:
    Hashtable accounts = new Hashtable();
    //do stuff to the hashtable
    FileOutputStream fos = new FileOutputStream("data.dat");
    ObjectOutputStream oos = new ObjectOutputStream(fos);
    oos.writeObject(accounts);
    //Program can be terminated from this point
    //there is no further oos.writeObject() if it wasn't terminated
    //immediately after the above writeObject() call
    //Program is ran again and at startup it checks for existing file
    File f = new File("data.dat");
    if(f.exists()){
    ObjectInputStream ois = new ObjectInputStream(new FileInpuStream(f));
    Object obj = obj.readObject(); //EOFException occurs here
    }Again those lines work perfectly fine if I do not terminate the program and I force it to check for an existing file. If I terminate, it's almost as if the program thinks there's nothing in "data.dat" eventhough it's obvious by my code that I did write something to "data.dat".

  • Problem with socket object writing

    hi,
    I made this little programm , with a class point , a server and a client.
    I try to send via the socket several point object.
    If send differents objects ( with several new point(... )) it works fine , but if i send the same object changing only the properties it doesn't work. Changing are not applicate.
    Here is the code.
    // POINT
    import java.io.Serializable;
    import java.awt.*;
    public class point implements Serializable{
        private int x_;
        private int y_;
        private Color c_;
        public point(int x, int y, Color c) {
           x_=x;
           y_=y;
           c_=c;
        public int get_x() { return x_ ; }
        public int get_y() { return y_ ; }
        public void set_x(int x) { x_=x ; }
        public void set_y(int y) { y_=y ; }
        public Color get_color() { return c_ ; }
    // SERVER
    import java.io.*;
    import java.net.*;
    public class s {
        public s()
            try
                ServerSocket server = new java.net.ServerSocket(80);
                java.net.Socket client  = server.accept();
                ObjectInputStream Istream_ = new ObjectInputStream(client.getInputStream());
                ObjectOutputStream Ostream_ = new ObjectOutputStream(client.getOutputStream());
                for(int i=0;i<4;i++)
                    point p_read = (point)Istream_.readObject();
                    System.out.print("x="+p_read.get_x());
                    System.out.println(" y="+p_read.get_y());
             catch (Exception exception) { exception.printStackTrace(); }
        public static void main(String args[])
         s s_ = new s();
    // CLIENT
    import java.io.*;
    import java.net.*;
    import java.awt.*;
    public class c {
        public c()
            try
                ipJDialog ipjd = new ipJDialog();
                String ip = ipjd.getvalue();
                Socket socket  = new Socket(ip,80);
                System.out.println("connection avec serveur reussi");
                ObjectOutputStream Ostream_ = new ObjectOutputStream(socket.getOutputStream());
                ObjectInputStream Istream_ = new ObjectInputStream(socket.getInputStream());
                point p1 = new point(50,50, new Color(255,0,0));
                Ostream_.writeObject(p1);
                point p2 = new point(22,30, new Color(255,0,0));
                Ostream_.writeObject(p2);
                point p3 = new point(8,7, new Color(255,0,0));
                Ostream_.writeObject(p3);
                point p4 = new point(2,1, new Color(255,0,0));
                Ostream_.writeObject(p4);
             catch (Exception exception) {exception.printStackTrace();}
        public static void main(String args[])
         c c_ = new c();
    // DIALOG TO GET IP FROM INPUTBOX
    import javax.swing.*;
    import java.awt.event.*;
    import java.awt.*;
    public class ipJDialog extends JDialog implements ActionListener {
        private String ip_;
        private JTextArea jta_;
        private JTextField jtf_;
        private JButton jb1_;
        public ipJDialog()
            this.getContentPane().setLayout(null);
            this.setTitle("Entrez l'IP du serveur");
            this.setSize(220,100);
            this.setModal(true);
            ip_= "localhost";
            jta_ = new JTextArea("IP du serveur :");
            jta_.setBounds(10,5, 90,20);
            jta_.setOpaque(false);
            jta_.setEditable(false);
            getContentPane().add(jta_);
            jtf_ = new JTextField();
            jtf_.setBounds(110,5, 90,20);
            jtf_.requestFocus();
            getContentPane().add(jtf_);
            jb1_ = new JButton("OK");
            jb1_.setBounds(10,30, 90,30);
            jb1_.addActionListener(this);
            getContentPane().add(jb1_);
            this.setVisible(true);
        public String getvalue() { return ip_ ; }
        public void actionPerformed(ActionEvent evt)
            String ChoixOption = evt.getActionCommand();
         if(ChoixOption.equals("OK"))
                ip_=jtf_.getText();
                this.setVisible(false);
    if I replace in client :
             point p1 = new point(50,50, new Color(255,0,0));
                Ostream_.writeObject(p1);
                point p2 = new point(22,30, new Color(255,0,0));
                Ostream_.writeObject(p2);
                point p3 = new point(8,7, new Color(255,0,0));
                Ostream_.writeObject(p3);
                point p4 = new point(2,1, new Color(255,0,0));
                Ostream_.writeObject(p4);
    by :
             point p = new point(50,50, new Color(255,0,0));
                Ostream_.writeObject(p);
                p.set_x(20);
                p.set_x(22);
                Ostream_.writeObject(p);
                p.set_x(55);
                p.set_x(32);
                Ostream_.writeObject(p);
                p.set_x(14);
                p.set_x(88);
                Ostream_.writeObject(p);
    I doesn't work , i receive a point with 50,50 ( the first one ) four times ...If you can explain me me why and what can I do ...
    Thx.

    For ObjectOutputStream, multiple references to a single object are encoded using a reference sharing mechanism so that graphs of objects can be restored to the same shape as when the original was written. State of a object will be recorded so that the ObjectOutputStream doesn't writes the same object to the outputstream when the object was refered by multiple references. So, when you tried to write the same object agains into the ObjectOutputStream, the ObjectOutputStream doesn't write the object, but passed the as a reference to the outputstream... In this case, on the other side, the ObjectInputStream will receive this reference and it will return the reference of this object (which is previous created when this object was passed over on the 1st time). This caused the ObjectInputStream will return a "unchanged" object even your object have changed before you write it agains to the ObjectOutputStream.
    My explaination maybe not that good... hope you can understand... :)

Maybe you are looking for

  • Problem with skype contacts added each time when I sync with my computer

    Dear Black Berry, I have a Business edition Black Berry Q10 model phone. The problem is I see duplicates of my skype contacts, day by day its getting worse. Im unable to find a solution for this. Need your help!!  How can I stop these contacts duplic

  • Problems with a simple stop watch program

    I would appreciate help sorting out a problem with a simple stop watch program. The problem is that it throws up inappropriate values. For example, the first time I ran it today it showed the best time at 19 seconds before the actual time had reached

  • Multiple Oracle Clients on Same Machine for different apps

    I was not able to find info that answered this so sorry if I missed something that explains this. At our site we have many applications some I know lots about some I'm not even aware of because we have mulitple sites. The application I develop uses a

  • Problem with zenmicro photo please he

    i have this player the 8 gb one, and today when i turned it on, all my songs are gone? does anyone know what could have happened or where they could be or if i can get them back? they just disappeared by themselves. its only two months old. i need to

  • LFA1 Table fields are not updated via IDOC for particular vendors

    Hello, We have a scenario where some of the additional vendor fields in transaction xk02 should be updated via inbound IDOC. The IDOC segments have the corresponding vendor field values in it. For particular vendors, the updation is not taking place