0
    if(server&&network){
    try{
       serverSocket = new ServerSocket(12345);
       socket = serverSocket.accept();
       System.out.println("Connected to " + socket.getInetAddress().getHostName());
       out = new ObjectOutputStream(socket.getOutputStream());
       in = new ObjectInputStream(socket.getInputStream());
       out.writeObject(lou);
       out.flush();
       out.reset();
       out.writeObject(dud);
       out.flush();
       out.reset();
       me = new Gen(lou, dud);
       //socket.close();
       //serverSocket.close();
    }catch(IOException ioException){
        ioException.printStackTrace();
    }
    }else if(network&&!server){
        try{
             //Socket socket = new Socket("10.69.18.244", 12345);
             socket = new Socket("192.168.1.100", 12345);
             //Socket socket = new Socket("10.69.18.162", 12345);
             out = new ObjectOutputStream(socket.getOutputStream());
             in = new ObjectInputStream(socket.getInputStream());
             lou = (ArrayList)in.readObject();
             //in.reset();
             dud = (ArrayList)in.readObject();
             //in.reset();
             me = new Gen(dud, lou);
             //socket.close();
        }catch(Exception ioException){
            ioException.printStackTrace();
        }
    }

当我尝试out.writeobject(lou)在服务器上使用时,我收到了 NullPointerException。客户端抛出一个NotSerializableException. 我不知道为什么,因为我在它上面初始化它。

4

1 回答 1

0

您想打开一个连接并在整个游戏中保持打开状态。

于 2013-02-08T15:04:49.050 回答