Java中的Socket编程关于多次输入输出的问题,希望给出解决方法

实现了多线程,这是服务端的代码:需求是接受客户端发送的数字,根据数字选择相应的case,当是1的时候要向服务端发送一个user的对象,ObjectInputStream ois=new ObjectInputStream(s.getInputStream());这句话的异常是java.io.EOFException at java.io.ObjectInputStream$PeekInputStream.readFully(ObjectInputStream.java:2281),

public void run()
    {
        ObjectOutputStream oos=null;
        int choice=0;
        try
            {
                InputStream is=s.getInputStream();
                choice=is.read();
                System.out.println("接受成功"+choice);
            } catch (IOException e1)
            {
                e1.printStackTrace();
            }
        switch (choice)
        {
            case 1:
                try
                  {
                      System.out.println("进入登录验证");
                      ObjectInputStream ois=new ObjectInputStream(s.getInputStream());_**
                        /* ObjectInputStream ois=new ObjectInputStream(s.getInputStream());这句话的异常是java.io.EOFException at java.io.ObjectInputStream$PeekInputStream.readFully(ObjectInputStream.java:2281),所以我就找到readFully(ObjectInputStream.java:2281)他的解释是
    void readFully(byte[] b, int off, int len) throws IOException {
        int n = 0;
        while (n < len) {
        int count = read(b, off + n, len - n);
        if (count < 0) {
            throw new EOFException();
        }
        n += count;
        }
    }_**
                */      
                      Object obj=ois.readObject();
                        OutputStream os=s.getOutputStream();
                        if(obj instanceof User)
                            {
                                User user=(User)obj;
                                String job=login(user);
                                os.write(job.getBytes());
                            }
                            os.close();
                            ois.close();
                     }
                    catch (Exception e1)
                        {
                            e1.printStackTrace();
                        } 

http://bbs.51cto.com/thread-1084435-1.html
http://bbs.51cto.com/thread-1085282-1.html

InputStream is=s.getInputStream();
choice=is.read();
因为你在读取choice的时候,如果只输入一个字节,那么s就读到了最后一个字节,即文件末尾

System.out.println("进入登录验证");
ObjectInputStream ois=new ObjectInputStream(s.getInputStream());
这里又从s中读取,所有抛出了EOFException异常,当输入过程中意外到达文件或流的末尾时,抛出此异常。

解决方法,new一个新的输入流,重新读取User信息
或者s中包含choice和User的信息