0

I'm programing client (android) server (java) application. In both client and server I'm using some classes that I create in third project and imported it as .jar file. When I'm running server side from eclipse everything works fine, but if I run .class files from terminal with (java className &) I'm starting to get

java.io.StreamCorruptedException: invalid type code: 2E

when server should read object that is imported from .jar file.

Code that read comming data on server side:

        try (
        ObjectOutputStream outToClient = new ObjectOutputStream(socket.getOutputStream());
        ObjectInputStream inFromClient = new ObjectInputStream(socket.getInputStream());
    ) {
        String inputLine, outputLine;
        checkClientStatus(outToClient);
        Object p;
    for(;;) {
            p = inFromClient.readObject();
            if(p instanceof String){
                String s = (String) p;
                if(s.equals("pong")) {
                    isClientAlive = true;
                    System.out.println("pong");
                }else{
                    System.out.println("You said:"+s);
                    outToClient.writeObject("You said:"+s);
                }
            }else if(p instanceof Position){
                System.out.println("pozicija");
            }
        }

    }catch (SocketTimeoutException exc){
        // you got the timeout
    }catch (EOFException exc){
        try {
            socket.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        // end of stream
    }catch (IOException exc){
        // some other I/O error: print it, log it, etc.
        exc.printStackTrace(); // for example
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    }

I'm assuming that binary files aren't builded correct or something?

Domen Jakofčič
  • 626
  • 1
  • 8
  • 24
  • Checkout http://stackoverflow.com/questions/1194656/appending-to-an-objectoutputstream/1195078#1195078 and http://stackoverflow.com/questions/2393179/streamcorruptedexception-invalid-type-code-ac – hagrawal7777 Dec 26 '16 at 00:41
  • thaks for suggestion, but I found problem. In eclipse I need to export my project as Runanble JAR file and check that all libraries shoud go into this JAR. – Domen Jakofčič Dec 26 '16 at 13:42

1 Answers1

0

I found problem. In eclipse I need to export my project as Runanble JAR file and check that all libraries shoud go into this JAR. – Domen Jakofčič

Armali
  • 18,255
  • 14
  • 57
  • 171