title: Simple Java Chat Program Help, Client Timesout when Connecting With Server
body: <p>I'm creating a very simple Java chat program, using the Java TCP sockets. I'm new to socket programming and Java. I cannot connect  with server, because every time the client connects to server it times out. Maybe, it is because I'm typing the wrong IP address——I don't know.</p>
  
  <p>Here is the code for the Server:</p>
  
  <pre><code>       try
         {
  
              int fport = Integer.valueOf(port.getText());
              ServerSocket server = new ServerSocket(fport);
              Socket socket = server.accept();
              msg.append("\\n Server is listening to port:" + port.getText());
              BufferedReader input = new BufferedReader( new InputStreamReader(socket.getInputStream()));
              PrintWriter out = new PrintWriter(socket.getOutputStream());
              out.print(msgtxt.getText());
              msg.append("\n\n" + input.readLine());
              msg.append("\n\n" + Nombre.getText() + msgtxt.getText());
  
  
         }
         catch (Exception ex)
         {
             msg.setText("\n\n" + "Error:" + ex.getMessage());
         }
  </code></pre>
  
  <p>Here is the code for the Client:</p>
  
  <pre><code>        try
          {
              int iport = Integer.valueOf(port.getText());
              int i1;
              int i2;
              int i3;
              int i4;
              i1 = Integer.valueOf(ip.getText());
              i2 = Integer.valueOf(ip1.getText());
              i3 = Integer.valueOf(ip2.getText());
              i4 = Integer.valueOf(ip3.getText());
              byte[] b = new byte[] {(byte)i1, (byte)i2, (byte)i3, (byte)i4 };
              InetAddress ipaddr = InetAddress.getByAddress(b);
              Socket sock = new Socket(ipaddr, iport);
              BufferedReader input = new BufferedReader(new InputStreamReader(sock.getInputStream()));
              BufferedWriter output = new BufferedWriter(new OutputStreamWriter(sock.getOutputStream()));
              output.write(m.getText());
              while(!input.ready()){}
              msg.setText("\n\n" + input.readLine());
              msg.setText("\n\n" + m.getText());
              output.close();
              input.close();
          }
          catch (Exception ex)
          {
              msg.setText("\n\n" + "Error: " + ex.getMessage());
          }
  </code></pre>