【JAVA】socket通信 客户端报错

public static void main(String[] args) {

 ConfigManager man=ConfigManager.getInstance();
 List group=man.getCommandGroup();
 List socket=null;
 try {
    ServerSocket server=new ServerSocket(9123);
    socket=new ArrayList();
    while (true) {
        server.setSoTimeout(5000);
        Socket sockcet= server.accept();
        socket.add(sockcet);
    }

} catch (IOException e) {
    // TODO Auto-generated catch block          
    e.printStackTrace();
}

 for (int i = 0; i < socket.size(); i++) {
        byte[] buf=OtherUtils.toSerialize(group.get(0));
        PackageFactory.write(buf, socket.get(i));
    }

}


客户端

 public static void main(String[] args) {
        try {
            Socket socket=new Socket("localhost", 9123);
            System.out.println(socket.isClosed());
            ObjectInputStream inputStream = new ObjectInputStream(new BufferedInputStream(socket.getInputStream()));
            CommandGroup group =(CommandGroup) inputStream.readObject();
            System.out.println(group.getLoop());
        } catch (UnknownHostException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

你可能感兴趣的:(java常见错误集锦,改错)