title: Problem with Chat client program
body: <p>I have a server chat and client chat programs running on localhost. When I try to connect to the server my client program freezes on next line <code>in = new ObjectInputStream(socket.getInputStream());</code> 
  here is a piece of code where I try to connect to the server</p>
  
  <pre><code>            Socket socket = new Socket(host, port);
              try {
                  out = new ObjectOutputStream(socket.getOutputStream());
                  in = new ObjectInputStream(socket.getInputStream());
                  Message m = new Message(null, nick, Message.Type.REGISTER);
                  out.writeObject(m);
                  out.flush();
              } catch (IOException ex) {
                  socket.close();
                  throw ex;
              }
  </code></pre>
  
  <p>Message class implements  Serializable interface, so it can be serialized over the network. And here is a piece of code where server hadle client request</p>
  
  <pre><code>try {
              ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(client.getInputStream()));
              Message m = (Message) in.readObject();
              switch (m.getMessageType()) {
                  case REGISTER:
                      registerUser(m);
                      break;
                  case CHATMESSAGE:
                      sendMessageToAll(m);
                      break;
                  case UNREGISTER:
                      unregisterUser(m);
                      break;
              }
          } catch (ClassNotFoundException ex) {
              Logger.getLogger(Chatserver.class.getName()).log(Level.SEVERE, null, ex);
          } catch (IOException ex) {
              Logger.getLogger(Chatserver.class.getName()).log(Level.SEVERE, null, ex);
          }
  </code></pre>
  
  <p>methods registerUser, unregisterUser, sendMessageToAll simply call next method</p>
  
  <pre><code>private void sendMessage(Message m, Socket s) throws IOException {
          ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(s.getOutputStream()));
          out.writeObject(m);
          out.flush();
         // out.close();
      }
  </code></pre>
  
  <p>Where is a mistake?</p>