ObjectInputStream+CipherInputStream hang

I've started a simple client-server app and had communication working fine untill I tried to add encryption.
Here's the faulty code with info on object initialization
// init in and out cipher
outCipher = Cipher.getInstance(algorithm);
outCipher.init(Cipher.ENCRYPT_MODE, key);
inCipher = Cipher.getInstance(algorithm);
inCipher.init(Cipher.DECRYPT_MODE, key);
// create ObjectInput/Output stream
cipherOut = new ObjectOutputStream(
new CipherOutputStream(socket.getOutputStream(), outCipher));
cipherIn = new ObjectInputStream( // <--- HANGS HERE
new CipherInputStream(socket.getInputStream(), inCipher));
My key is genereated just fine, and the ObjectOutputStream is created ok, it just hangs at cipherIn.
The only odd part about the output is this, which is outputted twice before each of the inCipher.init's are executed:
java.io.IOException: Caching not supported for http://www.tgpr.org/LlamaChat/
     at sun.plugin.cache.CachedJarLoader.download(CachedJarLoader.java:323)
     at sun.plugin.cache.CachedJarLoader.load(CachedJarLoader.java:131)
     at sun.plugin.cache.JarCache.get(JarCache.java:177)
     at sun.plugin.net.protocol.jar.CachedJarURLConnection.connect(CachedJarURLConnection.java:71)
     at sun.plugin.net.protocol.jar.CachedJarURLConnection.getJarFile(CachedJarURLConnection.java:56)
     at javax.crypto.SunJCE_e.run(DashoA6275)
     at java.security.AccessController.doPrivileged(Native Method)
     at javax.crypto.SunJCE_d.a(DashoA6275)
     at javax.crypto.SunJCE_d.a(DashoA6275)
     at javax.crypto.SunJCE_d.verify(DashoA6275)
     at javax.crypto.SunJCE_g.a(DashoA6275)
     at javax.crypto.SunJCE_b.a(DashoA6275)
     at javax.crypto.SunJCE_b.a(DashoA6275)
     at javax.crypto.Cipher.getInstance(DashoA6275)
     at ServerConnection.initializeCipher(ServerConnection.java:76)
     at SD_Key.performAction(SD_Key.java:14)
     at ServerConnection.<init>(ServerConnection.java:54)
     at LlamaChat.connect(LlamaChat.java:195)
     at LlamaChat.init(LlamaChat.java:78)
     at sun.applet.AppletPanel.run(AppletPanel.java:341)
     at java.lang.Thread.run(Thread.java:536)
can anyone help? I think i've tried everyting I can think of and i sure its possible to do this.
If you need more info to help, I'd be happy to provide :)
Thanks@
-Joe

Ok ... I was able to hack up the code a bit to break up getting the new ObjectInutStream, and it was able to execute the new CipherInputStream, but still hung on the new ObjectInputStream.
I took this a bit further and was able to transfer data over my Cipher(Input|Output)Stream.
I also tried different combinations of ordering the input and output and also tried comintations of Buffered(Input|Output)Streams on my other streams, but nothign worked :(
So ... I'm still in need of assistance.
Thanks!
- Joe

Similar Messages

  • RMI+JCE How to prevent the CipherInputStream hanging

    Dear sir/Madam,
    In our Rmi application, i bind the Server object with the JCE encryption,by implementing RMIClientSocketFactory,RMIServerSocketFactory.
    ie i bind like this
    RMIClientSocketFactory csf = new EncClientSocketFactory();
    RMIServerSocketFactory ssf = new EncServerSocketFactory();
    Remote stub = (Remote) UnicastRemoteObject.exportObject(( Remote) obj, 0, csf, ssf);
    Here i've overriden the createSocket method in both the classes.
    ie
    In "EncClientSocketFactory" the code look like this
    public Socket createSocket(String theHost, int thePort)
    throws IOException {
    Security.addProvider(new com.sun.crypto.provider.SunJCE());
    EncSocket encSocket = new EncSocket(theHost, thePort, key);
    return encSocket;
    In the Class "EncSocket" i've overriden InputStream and OutputStream methods.
    * Returns a stream of type XorOutputStream.
    public synchronized OutputStream getOutputStream() throws IOException {
    if(cos == null) {
    cos = new CipherOutputStream(super.getOutputStream(), outCipher);
    return cos;
    * Returns a stream of type XorInputStream.
    public synchronized InputStream getInputStream() throws IOException {
    if(cis==null) {
    cis = new CipherInputStream(super.getInputStream(), inCipher);
    return cis;
    while running the Server the Input and OutputStreams are created but at the time rebind,
    "m_registry.rebind(bindKey, stub);"
    the server is hanging or waiting in the InputStream.
    Your earliest reply is greatly appreciated.Iam breaking my head on this for the past one week.Million thanks for you.All the best
    Awaiting for ur reply
    kathiravan

    pls see http://forum.java.sun.com/thread.jsp?forum=58&thread=309785 for one of the solutions.
    Bill

  • Wrapping CipherStreams

    Hi
    I am having problems implementing CipherStreams. While encrypting objects with the Cipher-Class works perfectly fine, wrapping CipherStreams around ObjectStreams, or ObjectStreams around CipherStreams wont work. While i first tried to use the following:
    inputstream
    cipherinputstream(inputstream)
    objectinputstream(cipherinputstream)
    i tried to switch the cipher- and objectinputstream initialization, which in the end didnt change anything. What happens is:
    Both ways compile ( NetBeans 3.5 ), but in both cases the program stops executing when trying to wrap a cipherstream around an inputstream or an objectinputstream ( same goes for outputstreams of course ).
    No exception is being thrown, the program just stops.
    Any suggestions? :)

    Ah, thx for your answer. While in my working code, i first created the OutputStream, and then the InputStream, i switched the order when implementing the CipherStreams. I am going to test it now, i guess though, that was the problem.
    thx again, if this doesnt solve the problem, be sure to read again from me ;)
    thx, Ben

  • ObjectInputStream's readInt method hangs after waiting a long time...

    Hi there, I have a multi-threaded application that makes massive use of ObjectInputStream/ObjectOutputStream... Basically what it does is that a client server sends a request to an other server who treats the request and once it's done sends back a return code. Until now, those requests were executed under 5 minutes. My app has been in production for a few years now without any problems... I started having problems when new kinds of requests were executed ( these new requests can take up to 3 hours to execute ). So, the client server waits all this time for the return code using the readInt() function. When the request is 2 hours or more, it seems as if the stream hangs and the readInt() method doesn't receive anything ( Even though the writeInt() method was indeed executed ). Even more bizarre, is that no exception what so ever is raised.
    Anybody has an idea of what is going on here?
    Thanks to all!

    Are you sure you are flushing the output after the writeInt() on the server?

  • Server hangs up when tryin to read object Urgent Help Plz

    Hi,
    I've been working on a client-server model for a while, I've tested my applicaction a thousand of times locally (I mean, server and serveral clients running on the same machine) and it's ok, now I finally run server in a remote host and I find it rarely works fine, most of the times server hangs up when tryin to read objects I dont know why.
    this is the part of the server-code where the problem begins:
    public int EscucharSocket(){
            Socket cliente = null;
            System.out.println("Servidor en escucha...\n");
            while(true){
                try{
                    cliente = SocketS.accept();
                    //I get client's ip and port
                    String ip = cliente.getInetAddress().getHostAddress();
                    int puerto = cliente.getPort();
                    //After the conexion is made, server reads a signature to
                    //identify the client
                   //in function process I check if the signature is valid
                   //SignedData is a class where I wrap the signiture (obviously
                   //it implements Serializable interface
                   process((SignedData)le.LeerObject(cliente));
                   //Other things done here
                catch (Exception e) { }
    }le is a class I use to read,write data to the socket, this is the code of the LeerObject function
    public Object LeerObject(Socket c) throws Exception {
           //Here Is where the server hangs up
            ObjectInputStream b = new ObjectInputStream(c.getInputStream());
            return b.readObject();
    }As I wrote when running locally, there is no problem, but when I have a remote host, that happens
    Any help or idea?

    Hi again, thnx for your help
    I modified my LE class so I just create a couple of Input/Output Streams per client (on server n client program), this is now the complete code of the class:
    import java.net.*;
    import java.io.*;
    public class LE {
        DataOutputStream     dos;
        ObjectOutputStream  oos;
        DataInputStream        dis;
        ObjectInputStream     ois;
        //Streams are created just once in the constructor
        public LE (Socket s) throws Exception {
            dos = new DataOutputStream(s.getOutputStream());
             //I'm not sure if this flush has any sense
            dos.flush();
            oos = new ObjectOutputStream (s.getOutputStream());
            oos.flush();
            dis = new DataInputStream(s.getInputStream());
            ois = new ObjectInputStream (s.getInputStream());
        public void EscribirByte(byte datos[],int len) throws Exception {
            dos.write(datos,0,len);
            dos.flush();
        public void EscribirString(String dato) throws Exception {
            dos.writeUTF(dato);
            dos.flush();
        public void EscribirChar(char dato) throws Exception {
            dos.writeChar(dato);
            dos.flush();       
        public void EscribirInt(int dato) throws Exception {
            dos.writeInt(dato);
            dos.flush();
        public void EscribirLong(long dato) throws Exception {
            dos.writeLong(dato);
            dos.flush();
        public void EscribirObject(Object dato) throws Exception {
            oos.writeObject(dato);
            oos.flush();
        public String LeerString() throws Exception {       
            return dis.readUTF();
        public int LeerInt() throws Exception {       
            return dis.readInt();
        public char LeerChar() throws Exception {       
            return dis.readChar();
        public long LeerLong() throws Exception {       
            return dis.readLong();
        public Object LeerObject() throws Exception {       
            return ois.readObject();
    }part of code of server and client, where the conexion is made and the LE object is created
    Server:
    try{
           cliente = SocketS.accept();               
           //After accepting the conexion the LE object is created
            le = new LE(cliente);
            //I get client's ip and port
            String ip = cliente.getInetAddress().getHostAddress();
            int puerto = cliente.getPort();
            //Object wraping signature is read        
            process((SignedData)le.LeerObject());
            //other control operations doing here
            //A thread is created to receive requests from client
            //(reference to LE object is passed to the thread
           ConexionCliente c = new ConexionCliente (cliente,id_persona,id_grupo,tipo_usuario,backup,le);                               
            //thread is started
            c.start();
    catch (Exception e) {
        try {
            cliente.close();
        catch(Exception e2){}
    }Cliente code:
    try{
       //it connects to the server
       c=new Socket(host,puerto);
       //After accepting the conexion the LE object is created         
       le = new LE(c);
       //other things made here to genarate SignedData Object
      //It sends signed data object
      le.EscribirObject(Data);          
      //A thread is created and started to receive messages from server
      //reference to object LE is sent to the thread to avoid the need of
      //creating another
      new ConexionServidorClient(c,id_persona,ci,le).start();
      return 1;
    catch(Exception e) {
       return -1;
    }after the change, itworks a little better, but still most of the times server hangs up, I can't make server operational yet and I dont have any idea for solving this issue

  • ObjectInputStream acts strangely

    I'm on the verge of lunacy because of this program.
    Here's the problem: the execution reaches
    ObjectInputStream obin = new ObjectInputStream(socket.getInputStream());
    ObjectOutputStream obout = new ObjectOutputStream(socket.getOutputStream());on both client and server and then it just hangs forever. No exception, no nothing. I tried to see if it hangs on getting the stream or on wrapping it, and from my conclusion it's the wrapping that hangs. Wrapping with other streams (like) DataInputStream produces no error.
    I tried doing the very same thing in other (test) application, and it works like a charm. Is there something I'm not aware of here?
    Now, here's the code (it might seem large, but it's really simple, please take time to give it a look):
    SERVER
    Hashtable<String, ArrayList<Peer>> table = new Hashtable<String, ArrayList<Peer>>();
    private void accept(){
         try {
              //gets the connection and runs a PeerHandler thread, giving it the socket acquired from connection
              ServerSocket server = new ServerSocket(9000);
              System.out.println("Server is ready");
              while(true){
                   new PeerHandler(server.accept(), table).start();
         } catch (IOException e) {
                   e.printStackTrace();
    public static void main(String[] args) throws Exception{
              GlobalServer glob = new GlobalServer();
              byte[] adr = {127,0,0,35};
              ArrayList<Peer> ar = new ArrayList<Peer>();
              ar.add(new Peer(InetAddress.getByAddress(adr)));
              glob.table.put("somefile.crap.exe.hack", ar);
              glob.accept();
    }PEERHANDLER
    Socket socket;
    Hashtable<String, ArrayList<Peer>> table;
    public PeerHandler(Socket socket, Hashtable<String, ArrayList<Peer>> table){
         this.socket = socket;
         this.table = table;
    public void run(){
         try {
              //this is where it hangs
              ObjectInputStream obin = new ObjectInputStream(socket.getInputStream());
              ObjectOutputStream obout = new ObjectOutputStream(socket.getOutputStream());
              while(true){     
                   some code
         }catch (Exception e) {
                   e.printStackTrace();
    }CLIENT
    public static void main(String[] args) {
         try {
              Socket s = new Socket("127.0.0.1", 9000);
              //this hangs as well               
              ObjectInputStream obin = new ObjectInputStream(s.getInputStream());
              ObjectOutputStream obout = new ObjectOutputStream(s.getOutputStream());
              //the following code is probably no longer relevant to the problem               
              Message m = new Message("FIND", "somefile");
              obout.writeObject(m);
              Message mm = (Message)obin.readObject();               
              } catch (Exception e) {
                   e.printStackTrace();
    }

    ObjectInputStream obin = new ObjectInputStream(socket.getInputStream());
    ObjectOutputStream obout = new ObjectOutputStream(socket.getOutputStream());You need to reverse the order of those lines in either the server or the client.
    The moment you create an object input stream it tries to read a stream header from the underlaying stream. This means that both the server and the client stay wait for the other one to do something eternally. The fix is to make either the client or the server (but not both) create the output stream first.

  • TopicConnection.createSession hanging

    Hi everyone,
    We're expermenting with Oracle AQ as JMS provider, since we're using an Oracle DB (specifically Oracle Database 11g Release 11.1.0.0.0 - Production) underneath anyway. We managed to connect using a "toy" application which also receives messages. However, in our "real" applications, we can get a ConnectionFactory, use that to create that Connection, start the Connection, but when creating a Session, the Thread is just hanging up.
    Here's a code snippet:
    final TopicConnection con = AQjmsFactory
    .getTopicConnectionFactory("<hostIP>",
    "<SID>",
    <port>,
    "thin")
    .createTopicConnection("<aqUser>",
    "<aqUserPassword>");
    con.start();
    final AQjmsSession session = (AQjmsSession) con.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
    As mentioned above, createTopicSession is hanging and never returns.
    We managed to extract the StackTrace for the hanging Thread:
    "AWT-EventQueue-0" Id=19 in RUNNABLE (running in native)
    java.net.SocketInputStream.socketRead0(Native Method)
    java.net.SocketInputStream.read(SocketInputStream.java:129)
    java.io.ObjectInputStream$PeekInputStream.read(ObjectInputStream.java:2265)
    java.io.ObjectInputStream$PeekInputStream.readFully(ObjectInputStream.java:2278)
    java.io.ObjectInputStream$BlockDataInputStream.readShort(ObjectInputStream.java:2749)
    java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:779)
    java.io.ObjectInputStream.(ObjectInputStream.java:279)
    fr.dyade.aaa.jndi2.client.NamingConnection.open(NamingConnection.java:100)
    fr.dyade.aaa.jndi2.client.NamingConnection.invoke(NamingConnection.java:75)
    fr.dyade.aaa.jndi2.client.NamingContextImpl.lookup(NamingContextImpl.java:106)
    javax.naming.InitialContext.lookup(InitialContext.java:392)
    oracle.jms.EmulatedXAHandler.(EmulatedXAHandler.java:69)
    oracle.jms.AQjmsSession.(AQjmsSession.java:364)
    oracle.jms.AQjmsConnection.createTopicSession(AQjmsConnection.java:739)
    As you can see, apparently the AQ code is trying a lookup inside the client JVM's default JNDI context (which is a Joram messaging server - exactly the one we're planning to replace, but we'll still need it for now). We're a bit lost here and open for suggestions.

    What version of OC4J are you using? Remember that OC4J JMS is only fully supported starting in 904 (developer release is OK).
    If you are using the 904 developer release, try to get a stack trace of the client and server JVMs (send them a SIGKILL).

  • Help on PBE and cipherInputStreams

    Hello, I have a program where I want to encrypt a Hashtable with PBE, and store the result in a file. This seems to work ok. The problems are when I want to read the file, decrypt it and turn the data into a hashtable again.. To do this, I take the result from a CipherInputStream and stores it in a ByteArrayOutputStream. Then I make a ByteArrayInputStream, with the buffer from ByteArrayOuputSTream as input, and put this in a ObjectInputStream. Then I read and stores it in a hashtable.
    When I run it, I get a java.EOFException. It seems like the CipherInputStream won't read :|
    Here is my code, I hope it makes sence.... Could someone please see what is wrong?
    import java.math.*;
    import java.io.*;
    import java.util.*;
    import java.util.zip.*;
    import java.security.*;
    import java.security.spec.*;
    import javax.crypto.*;
    import javax.crypto.spec.*;
    public class testalle{
        static byte[] salt;
        static int iterationcount;
        public static void main(String[] args){
         testalle mytest = new testalle();
         //salt and iterationcount used for PBE of keyrings
         salt = new byte[8];
         salt[0] = (byte)0x01;
         salt[1] = (byte)0x23;
         salt[2] = (byte)0x45;
         salt[3] = (byte)0x67;
         salt[4] = (byte)0x89;
         salt[5] = (byte)0xab;
         salt[6] = (byte)0xcd;
         salt[7]  =(byte)0xef;
         iterationcount = 1024;
         Hashtable mytable = new Hashtable();
         mytable.put(new Integer(1), new Integer(1));
         mytable.put(new Integer(2), new Integer(2));
         mytable.put(new Integer(3), new Integer(3));
         char[] password = {'a','b', 'c', 'd'};
         try{
         File myFile = new File("hashtabletoarray");
         myFile.createNewFile();
         mytest.hashtableToArray(myFile, password, mytable);
         mytest.arrayToHashtable(myFile, password);
         catch(IOException io){
             System.out.println(io);
        /* Want to take a hashtable, encrypt it using PBE, and store it in myFile*/
        void hashtableToArray(File myFile, char[] password, Hashtable tabell){
         try{
             FileOutputStream fout = new FileOutputStream(myFile);
             PBEKeySpec keyspec = new PBEKeySpec(password);
             PBEParameterSpec paramspec = new PBEParameterSpec(salt,iterationcount);
             SecretKeyFactory skf = SecretKeyFactory.getInstance("PBEWithMD5AndDES");
             SecretKey key = skf.generateSecret(keyspec);
             Cipher cipher = Cipher.getInstance("PBEWithMD5AndDES");
             cipher.init(Cipher.ENCRYPT_MODE,key,paramspec);
             CipherOutputStream cout = new CipherOutputStream(fout,cipher);
             //turnes the hashtable into a array of bytes
             byte[] tabellarray = (tabell.toString()).getBytes("UTF-8");
             cout.write(tabellarray);
             fout.close();
             cout.close();
         catch(FileNotFoundException fnf){
             System.out.println(fnf);
         catch(IOException io){
             System.out.println(io);
         catch(NoSuchAlgorithmException nsa){
             System.out.println(nsa);
         catch(InvalidKeySpecException iks){
             System.out.println(iks);
         catch(InvalidKeyException ik){
             System.out.println(ik);
         catch(NoSuchPaddingException nsp){
             System.out.println(nsp);
         catch(InvalidAlgorithmParameterException iap){
             System.out.println(iap);
        /* Want to read in a File, decrypt it with PBE, and store what was in the file as a hashtable */
        void arrayToHashtable(File myFile, char[] password){
         try{
             FileInputStream finp = new FileInputStream(myFile);
             PBEKeySpec keyspec = new PBEKeySpec(password);
             PBEParameterSpec paramspec = new PBEParameterSpec(salt,iterationcount);
             SecretKeyFactory skf = SecretKeyFactory.getInstance("PBEWithMD5AndDES");
             SecretKey key = skf.generateSecret(keyspec);
             Cipher cipher = Cipher.getInstance("PBEWithMD5AndDES");
             cipher.init(Cipher.DECRYPT_MODE,key,paramspec);
             CipherInputStream cin = new CipherInputStream(finp,cipher);
             ByteArrayOutputStream bout = new ByteArrayOutputStream();
             //read in from cin, and store the plaintext in bout
             byte[] buffer = new byte[8192];
             int length = cin.read(buffer);
             System.out.println(length);
             while (length > 0) {
              bout.write(buffer,0,length);
              length = cin.read(buffer);
             byte[] received = bout.toByteArray();
             bout.close();
             cin.close();
             //make a inputstream to put in a objectInputStream
             ByteArrayInputStream binp = new ByteArrayInputStream(received);
                    ObjectInputStream oinp = new ObjectInputStream(binp);
             Hashtable tabell = (Hashtable)oinp.readObject();
             oinp.close();
         catch(FileNotFoundException fnf){
             System.out.println(fnf);
         catch(IOException io){
             System.out.println(io);
         catch(NoSuchAlgorithmException nsa){
             System.out.println(nsa);
         catch(InvalidKeySpecException iks){
             System.out.println(iks);
         catch(InvalidKeyException ik){
             System.out.println(ik);
         catch(NoSuchPaddingException nsp){
             System.out.println(nsp);
         catch(InvalidAlgorithmParameterException iap){
             System.out.println(iap);
         catch(ClassNotFoundException cnf){
             System.out.println(cnf);
    }

    That was what I wanted to do at first, but the
    problem is that CipherOutputStream only has
    write(byte[] b) method, not a writeObjetc method.. So
    I cannot put the ObjectOutputStream inside a
    CipherOutputStream. It doesn't work the other way
    around either, the ObjectOutputStream cannot take a
    CipherOutputStream as input.. as far as I could tell..ObjectOutputStream takes an OutputStream in it's constructor. A CipherOutputStream is an OutputStream since it is derived from it.

  • Socket.getInputStream hangs

    I have a simple client/server app, and the client hangs when I try to get the input stream coming out of the server. I have the following code on the server:
    ObjectOutputStream oos = null;
    ObjectInputStream ois = null;
    port = 49152;
    server = new ServerSocket(port, 0, InetAddress.getLocalHost());
    sock = server.accept();
    oos = new ObjectOutputStream(sock.getOutputStream());
    ois = new ObjectInputStream(sock.getInputStream());
    String inMsg = (String) ois.readObject();
    oos.writeObject(outMsg);
    oos.close();
    ois.close();
    sock.close();And I try to invoke it with this code on the client:
    ObjectOutputStream oos = null;
    ObjectInputStream ois = null;
    String inMsg = "";
    int port = 49152;
    try {
         Socket sock = new Socket(InetAddress.getLocalHost(), port);
         oos = new ObjectOutputStream(sock.getOutputStream());
         ois = new ObjectInputStream(sock.getInputStream());//the code hangs here
         oos.writeObject(outMsg);
         inMsg = (String) ois.readObject();
            oos.close();
         ois.close();
         sock.close();
    } catch (Exception e) {
         return "";
    return inMsg;
         The code hangs where indicated in the comments. Can someone tell me what I'm doing wrong?
    Edited by: MidnightJava on Apr 10, 2008 4:55 AM

    Can you please explain the rationale for your suggestion? What sort of problem is it addressingThe constructor for ObjectOutputStream writes a header to the stream. The constructor for ObjectInputStream reads it. Try constructing them in the opposite order at both ends and you will see a lovely deadlock. The flush() is required if there is a BufferedOutputStream under the ObjectOutputStream.
    is it a good idea to do it always when creating streams from a socket?It's essential when dealing with object streams. Other streams, no.

  • CipherInputStream Creation

    When I try to create a CipherInputStream with Blowfish my program just stops doing anything, but when I create a CipherOutputStream everything works fine. I don't know whats going on, here's the source code.
    Cipher decryptor = Cipher.getInstance("Blowfish/ECB/PKCS5Padding");
    decryptor.init(Cipher.DECRYPT_MODE, secret);
    cis = new ObjectInputStream(new CipherInputStream(ois, decryptor));Any helps appreciated

    There is nothing wrong with what you have.. Where does ois come from? Do you actually do readObject().. Don't mean to demean here but the three lines of code you have posted have no issues so long as the above questions aren't the problem...

  • (ObjectInputStream) first time it works, second time I get an error!

    hi,
    Using the following code I am sending a query to a server socket using a PrintWriter.println function and retrieve a vector object (results).
    Client Code
         public Vector getDBResultSet(String query) throws ClientException, IOException{
              Object obj = new Object();
              if (socket != null)
                   try{                    
                        System.out.println("Sending "+query+" to Server");
                        writer.println(query);
                        try{
                             ois = new ObjectInputStream(input);
                             while ((obj = ois.readObject()) != null)
                                  obj = ois.readObject();
                        }catch (EOFException eofx){
                             System.out.println("EOF @ object input stream!");
                        finally{
                             ois.close();
                        return (Vector)obj;
                   }catch(Exception e){
                        e.printStackTrace();
                        throw new ClientException("<html>Error: <br>"+e.toString()+"#"+e.getMessage()+"</html>");
                   }finally{
                        //writer.close();
              }else throw new ClientException("no connection!");
         }Server side code
         public void communicate()
              try{          
                   while (true){
                        String q = reader.readLine();
                        Vector vec = db.getResults(q);
                        oos = new ObjectOutputStream(output);
                        oos.writeObject(vec);
                        oos.flush();
                        oos.close();
              }catch(Exception e){
                   e.printStackTrace();
         }First time everything goes OK.
    Second time on the Client-Side I get strange errors like "ClassCastException Java.lang.Object" and if I comment out the "while" line I get a "socket closed" error...
    any ideas what is wrong with it?

    Thank you. input and output variables are Inputstream and outputStream objects.
    However if you notice, I open the ObjectInputStream inside getDBResultSet() method. So whenever this method is called a new ObjectIputStream shall be initialized. That is why I close the ObjectInput/outputStreams right after the try/catch portion.
    I tried starting the ObjectInputStream inside the connect method (which initialized the connection with the ServerSocket object) but wheneven connect() was called the GUI hanged!
    I don't know what am I doing wrong...
         public void connect() throws Exception
              if (socket == null){
                   try{
                        System.out.println("opening connection...to "+host+" at port "+port);
                        socket = new Socket(host, port);
                        input = socket.getInputStream();
                        output = socket.getOutputStream();
                        in = new DataInputStream(input);
                        out = new DataOutputStream(output);
                        reader = new BufferedReader(new InputStreamReader(in));
                        writer = new PrintWriter(out, true);          
                        //ois = new ObjectInputStream(input);
                        System.out.println("Connection established!");
                   }catch(IOException e){
                        try{
                             if (socket != null)
                                  socket.close();
                             System.out.println("ERROR WHILE CONNECTING... SOCKET IS NOW CLOSED!");
                        }catch(IOException x){
                             x.printStackTrace();
              else
                   throw new ClientException("connection active!");
         }

  • ObjectInputStream() returning null and EOFException - need help

    I have been working on this little snippet of code all day and I cannot understand why I get null values when I run a display application. The code is posted below for 3 file. PhoneList.java is for serialization. CreatePhoneList is to populate a saved file with phone numbers and names of contacts. DisplaySavedPhoneList.java is to display the saved names and numbers. I'm not looking for the correct code, put for someone to point me in the right direction on why I'm getting these results so I can find a solution.
    Here is the PhoneList class:
    import java.io.*;
    public class PhoneList implements Serializable
        private String name;
        private String num;
        private String phName;
        private String phNum;
        PhoneList(String phNum, String phName)
            setName(phName);
            setNum(phNum);
        public String getName()
            return phName;
        public String getNum()
            return phNum;
        public void setName(String phName)
            name = phName;
        public void setNum(String phNum)
            num = phNum;
    }Here is the CreatePhoneList class
    import java.io.*;
    import java.util.*;
    public class CreatePhoneList
        public static void main(String[] args) throws IOException
            ObjectOutputStream output = new ObjectOutputStream(new FileOutputStream("PhoneList.txt"));
            PhoneList list;
            String phName;
            String phNum;
            final String QUIT = "QUIT";
            Scanner in = new Scanner(System.in);
            System.out.println("Enter a phone number or " + QUIT + " to quit.");
            phNum = in.next();
            while(!phNum.equals(QUIT))
                System.out.println("Enter the contact name.");
                phName = in.next();
                list = new PhoneList(phNum, phName);
                output.writeObject(list);
                System.out.println("Enter a phone number or " + QUIT + " to quit.");
                phNum = in.next();
            output.close();
    }and this is the DisplaySavedPhoneList class:
    import java.io.*;
    import java.util.*;
    public class DisplaySavedPhoneList
        public static void main(String[] args) throws IOException, ClassNotFoundException
            ObjectInputStream input = new ObjectInputStream(new FileInputStream("PhoneList.txt"));
            PhoneList list;
            final int SHOW = 1;
            int showList;
            int count = 0;
            Scanner in = new Scanner(System.in);
            try
                System.out.print("To display Phone List enter " + SHOW);
                showList = in.nextInt();
                while(showList == SHOW)
                    list = (PhoneList)input.readObject();
                    System.out.println("Name: " + list.getName() + " Phone Number: " + list.getNum());
                    count++;
            catch(EOFException e)
                System.out.println("Oops, something broke!");
                input.close();
    }This is the result from running the DisplaySavedPhoneList application:
    To display Phone List enter 1
    1
    Name: null Phone Number: null
    Name: null Phone Number: null
    Oops, something broke!

    ok, I did that, and its pointing me to the line commented below. I did a practical exercise where the code was almost identical and it worked fine. The only difference are the variables.
    try
                System.out.print("To display Phone List enter " + SHOW);
                showList = in.nextInt();
                while(showList == SHOW)
                    list = (PhoneList)input.readObject(); //this is the line that was identified in the stacktrace
                    System.out.println("Name: " + list.getName() + " Phone Number: " + list.getNum());
                    count++;
            catch(EOFException e)
                System.out.println("Stack Trace");
                e.printStackTrace();
                input.close();
            }here is the total stack trace, in case you were wondering...
    To display Phone List enter 1
    1
    Name: null Phone Number: null
    java.io.EOFException
    Name: null Phone Number: null
    Stack Trace
            at java.io.ObjectInputStream$BlockDataInputStream.peekByte(ObjectInputStream.java:2554)
            at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1297)
            at java.io.ObjectInputStream.readObject(ObjectInputStream.java:351)
            at DisplaySavedPhoneList.main(DisplaySavedPhoneList.java:21)I'm still not quite sure what this is telling me though.

  • My Excel with PowerPivots acts weird, it hangs when i try to change font color

    Hi 
    I am facing a weird issue using PowerPivot in my workbook, there is a worksheet named Charts in my workbook and all the charts i am using resides in that worksheet. Whenever i try to change the font color in that sheet, my excel's color palette goes blur
    and then everything just freezes and turns black. This problem is happening only with Charts worksheet, when i try to change the color in other sheets, it works just, the problem is only with Charts sheet. File
    size is 16 MB, there are just 10 pivot tables with some calculations and some calculated fields. There are no add-ins other than PowerPivot. 
    Thanks,
    Shanker

    Hi,
    In regarding of the issue, please provide us more information to assist you better.
    Do you receive any error message?
    Which Excel version are you using?  Excel 2013 or other?
    Which workbook format are you using? XLS or XLSX?
    Are you performing any specific task?
    According to your description, this issue seems only occur with the special worksheet "Charts".
    Firstly, I recommend we copy all of the content to a new/blank Excel file to test.
    If it works fine, this issue might be caused by the "Charts" workbook itself. We'd better check the "Charts" workbook. Or re-build the file with a new workbook.
    If it still makes Excel hang with a new file, this issue might due to the content. Please check the content first.
    Secondly, we could follow below KB to troubleshoot this issue:
    https://support2.microsoft.com/kb/2758592/en-us?wa=wsignin1.0
    Thirdly, if the issue still exists, we may try to collect the Event log and App crash dump file to do advanced troubleshooting.
    Event log:
    http://windows.microsoft.com/en-US/windows7/Open-Event-Viewer
    App crash dump file:
    First enable app crash dump collection by copying following words into notepad, saving it as dump.reg and importing
    it:
    Windows Registry Editor Version 5.00
    [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\Windows Error Reporting\localdumps\EXCEL.EXE]
    "DumpFolder"=hex(2):63,00,3a,00,5c,00,63,00,72,00,61,00,73,00,68,00,64,00,75,\
      00,6d,00,70,00,73,00,00,00
    "DumpCount"=dword:00000010
    "DumpType"=dword:00000001
    "CustomDumpFlags"=dword:00000000
    Then, open Excel
    to repro the issue. If crash issue appeared, please find the crashdump file under c:\.
    To further help you, please upload this file into Skydrive and shared the link here.
    Also, you can try to analyze dump by yourself if you would like to:
    How to analyze app crash dump file:
    http://blogs.technet.com/b/askperf/archive/2007/05/29/basic-debugging-of-an-application-crash.aspx
    Hope it's helpful.
    Regards,
    George Zhao
    TechNet Community Support
    It's recommended to download and install
    Configuration Analyzer Tool (OffCAT), which is developed by Microsoft Support teams. Once the tool is installed, you can run it at any time to scan for hundreds of known issues in Office
    programs.

  • Just installed Firefox 4. It hangs when I open any website and type in, for example, an ID, or even just click on something, for example, "Compose", in my webmail site.

    Here's the detail of what happens.
    1. Turn on computer and then click on Firefox icon on desktop.
    2. Firefox opens. Everything looks OK. Mr Bunsen's graphic is working fine.
    3. Click on any webpage link. For example, a newspaper or an online webmail page. All looks OK until
    4. Click on anything or type anything, such as in ID in a box, and bingo, the top line of Firefox goes from dark blue to very pale blue and the computer is hung. You cannot get out of Firefox or get Firefox to work.
    5. Switch off computer.
    Is this perhaps due to a clash of Add-ons. I run Avast anti-virus. McAfee came with Firefox 4 and I did not reject it. Is it conflicting wth something in my system and causing it to hang?

    You can modify the pref <b>keyword.URL</b> on the <b>about:config</b> page to use Google's "I'm Feeling Lucky" or Google's "Browse By Name".
    * Google "I'm Feeling Lucky": http://www.google.com/search?btnI=I%27m+Feeling+Lucky&ie=UTF-8&oe=UTF-8&q=
    * Google "Browse by Name": http://www.google.com/search?ie=UTF-8&sourceid=navclient&gfns=1&q=
    * http://kb.mozillazine.org/keyword.URL
    * http://kb.mozillazine.org/Location_Bar_search

  • I upgraded to the latest version of Firefox but it hangs when I use a search site such as Google or Bing. How can I fix this?

    putting a search option in the search box to the right of the address bar opens up the full search window but then Firefox hangs.

    Your UserAgent string in Firefox is messed up by another program that you installed, and those websites don't know you are running Firefox 3.6.3 (which is what you do have installed).
    [http://en.wikipedia.org/wiki/User_Agent]
    type '''about:config''' in the URL bar and hit Enter
    ''If you see the warning, you can confirm that you want to access that page.''
    Filter = '''general.useragent.'''
    Right-click the preferences that are '''bold''', one line at a time, and select '''''Reset''''',
    Then restart Firefox

Maybe you are looking for

  • Print Module - Page Panel: Page options & Photo Info lost

    In the print module there are only 4 features left now in my final release version of LR3: 1. Page Background colour 2. Identity Plate 3. Watermarking 4. Cut Guides. Victoria Bampton described also the features with a screenshot of LR3b2 in her "Miss

  • (ID 43 Details: Internal error code: 0x8099090E) and (ID 60 Details: Internal error code: 0x809909B0)

    Hi, I have a problem with one DPM 2012 SP1 installed on Windows 2012 R2 server with SQL installed locally on the server. We have installed this server for about 1 month ago and almost every job work grate until now. The May 17 there were a DPM Rollup

  • Print GregorianCalendar using JSTL

    I have a GregorianCalendar property (for example exchange.rateDate) and I want to print it in a jsp page using jstl tags. How can I solve this problem? liviu

  • Datapump & max roles exceeded

    So, I was trying to export a schema out of a newly installed 10.1.0.4 instance, something I've done repeatedly in a 10.1.0.3 instance, using the following parmfile [oracle@linux-test transport]$ more expdp_audits.par SCHEMAS=audits LOGFILE=expdpdvlp_

  • Update Multiple rows

    I need to update like 500 records in the same table, one column. How do I do it using update or shall I need to write pl/sql Thank You