ObjectInputStream readInt() 不工作

ObjectInputStream readInt() isn't working

我无法执行 readInt() 但 readObject 工作正常。给我一些解决方案。 我在服务器端使用以下代码:

ObjectInputStream din = new ObjectInputStream(s.getInputStream());
ObjectOutputStream dout = new ObjectOutputStream(s.getOutputStream());
     s1 = (String) din.readObject();
        switch (s1) {
           case "signin":
                    int a = din.readInt();
                    dout.writeInt(3);
                    System.out.println(a);
                    Mobile = (String) din.readObject();
                    String Pass = (String) din.readObject();
                      dout.writeInt(1);
                    break;
           }

我的客户端代码是:-

 public int getAuthenticate(final String Mobile, final String Pass,final String signin)
{
    m_objThreadClient=new Thread(new Runnable() {
        public void run()
        {

            try
            {
                clientSocket= new Socket(ipAddress,11);
                oos = new ObjectOutputStream(clientSocket.getOutputStream());
                ObjectInputStream ois =new ObjectInputStream(clientSocket.getInputStream());
                oos.writeObject(signin);
                oos.writeInt(2);
                status = ois.readInt();
                System.out.println(status);
                oos.writeObject(Mobile);
                oos.writeObject(Pass);
                status = ois.read();
                System.out.println("Server status="+status);
            }
            catch (Exception e)
            {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

        }
    });

  m_objThreadClient.start();

   try{m_objThreadClient.join();}
   catch (Exception e){e.printStackTrace();}
           return status;
}

在执行这些时,我既不打印 'status' 的值,也不打印 'a' 的值。它只是挂起。如果我删除 readInt() 或 read() 它工作正常。

尝试

oos.writeObject(signin);
oos.flush();
oos.writeInt(2);
oos.flush();

希望它能奏效。