title: How I can send a object from server to Client in Java?
body: <p>hi i want to create a java programm that send objects and get Objects from a server. </p>
  
  <p>For this I create two classes: </p>
  
  <p>If i send a object from client to server it works but how i can send a object from server to client? :/ </p>
  
  <p>ClientManager: </p>
  
  <pre><code>public class ClientManager {
      private String server;
      private int port;
  
      //Streams für Serialisierte Objekte
      private ObjectInputStream inputObjectStream = null; 
      private ObjectOutputStream outputObjectStream = null; 
  
      //Konstruktor: Server und Port werden benötigt
      public ClientManager(String server,int port){
          this.server = server;
          this.port = port;
      }
  
      //Sendet ein Object an eine Serverinstanz
      public void sendObjectToServer(Object obj){
          try(Socket socket = new Socket(server,port)){
  
              outputObjectStream = new ObjectOutputStream(socket.getOutputStream());
              outputObjectStream.writeObject(obj);
  
              outputObjectStream.flush();
              outputObjectStream.close();
  
          } catch (IOException ex) {
              ex.printStackTrace();
          }
      }
  
      //Bekommt ein Object von einer Serverinstanz 
      public Object getObjectFromServer(){
          return new Object();
      }
  }
  </code></pre>
  
  <p>ServerManager: </p>
  
  <pre><code>public class ServerManager {
  
      private final int port; //Portnummer
  
      private Socket socket = null;
  
      private ObjectInputStream inputStream = null; //Objekt vom Client
      private ObjectOutputStream outputStream = null; //Objekt an Client
  
      private Object obj; //Objekt das übers Netzwerk gesendet wird
  
      //Konstruktor
      public ServerManager(int port){
          this.port = port;
      }
  
      //Bekommt ein Objekt von einem Client
      public Object getObjectFromClient(){
  
          try(ServerSocket serverSocket = new ServerSocket(port)) {
              socket = serverSocket.accept();
  
              inputStream = new ObjectInputStream(socket.getInputStream());
  
              obj = inputStream.readObject();
  
              socket.close();
  
          } catch (Exception e) {
              e.printStackTrace();
          }
  
          return obj;
      }
  
      public void sendObjectToClient(Object obj){
          //Muss noch erstellt werden
      }
  
  }
  </code></pre>