title: Can't connect to another pc (another IP)using JAVA
body: <p>i am trying to connect with Client Class to server that uses in another computer
  with another IP...i wrote the ip of the server and the same port in the Socket but there isn't connection...I succeed to connect to the server when i run the server and the Client in the same computer but when i wrote 127.0.0.1 in the ip</p>
  
  <p>sorry on my lame english...</p>
  
  <p>Server class:</p>
  
  <pre><code>import java.awt.BorderLayout;
  import java.awt.Color;
  import java.awt.event.ActionEvent;
  import java.awt.event.ActionListener;
  import java.io.*;
  import java.net.Socket;
  import javax.swing.*;
  
     public class ClientSide   {
     Socket client;
     ObjectOutputStream out1;
  
    //////////////////////
  JFrame frame=new JFrame("Client");
  JTextArea ta=new JTextArea(20,10);
  JButton btn=new JButton("Enter");
  JTextArea send=new JTextArea(10,5);
   ///////////////////////
  
  
               /////Gui////
        ClientSide(){
  
       frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
       frame.setVisible(true);
       frame.setSize(600,500);
  
       JPanel p=new JPanel(new BorderLayout());
       frame.add(p);
       JScrollPane spta=new JScrollPane(ta);
       p.add(btn,BorderLayout.EAST);
       p.add(spta,BorderLayout.CENTER);
       p.add(send,BorderLayout.SOUTH);
       ta.setBackground(Color.cyan);
       frame.revalidate();
               ////set Client//
       try {      
          client=new Socket("127.0.0.1",8080);
  
          ta.setText("            -Connection-");
  
          ////set Output/////
           out1=new ObjectOutputStream( client.getOutputStream());
           out1.flush();
  
  
  
           btn.addActionListener(new ActionListener() {
  
  
              public void actionPerformed(ActionEvent arg0) {
                  try {
                      out1.writeObject(send.getText());
                      out1.flush();
                      ta.setText(ta.getText()+"\nYou:"+send.getText());
  
                  } catch (IOException e1) {
                      e1.printStackTrace();
                  }
  
                    if (send.getText().equals("Bye"))
  
                           try {
                               client.close();
                               frame.dispose();
                          } catch (IOException e) {
                              e.printStackTrace();
                          }
  
              }
          });
  
           //////set Input////
           ObjectInputStream in = new ObjectInputStream(client.getInputStream());
           Object inputLine; ;
  
  
           while(true){
               try {
                   out1.flush();
                  inputLine = in.readObject();
                  if(inputLine!=null){
                      ta.setText(ta.getText()+"\nClient:"+inputLine);
                      }
              } catch (ClassNotFoundException e) {
                  e.printStackTrace();
              }
               }
  
  
  
  
      } catch (IOException e) {
          e.printStackTrace();
      }
      }
  
  
  public static void main(String[] args) {
  
              new ClientSide();
  
  
    }
    }
  </code></pre>
  
  <p>Client class:</p>
  
  <pre><code>import java.awt.*; 
  import java.awt.event.*;
  import java.io.*;
  import java.net.ServerSocket;
  import java.net.Socket;
  import javax.swing.*;
  
  
  
   public class ServerSide    {
  ObjectOutputStream  out;
  ServerSocket ss;
  Socket so;
  JFrame frame=new JFrame("Server");
  ///////
  JTextArea ta=new JTextArea(20,10);
  JTextArea send=new JTextArea(10,5);
  JButton enter=new JButton("Enter");
      ////set Gui////
  
       ServerSide(){
   frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
   frame .setVisible(true);
   frame. setSize(600,500);
  
   JPanel p=new JPanel(new BorderLayout());
   frame. add(p);
   JScrollPane spta=new JScrollPane(ta);
  
    p.add(enter,BorderLayout.EAST);
    p.add(spta,BorderLayout.CENTER);
    p.add(send,BorderLayout.SOUTH);
    ta.setBackground(Color.cyan);
    frame.revalidate();
  
   /////Server///
      try {
       int port=8080;
        System.out.println(port);
      ss = new ServerSocket(8080);
      so=ss.accept();
      ta.setText(ta.getText()+"\n            -Connection-");
       /////set Output////
        out = new ObjectOutputStream(so.getOutputStream());
        out.flush();
  
       enter.addActionListener(new ActionListener() {
  
          public void actionPerformed(ActionEvent arg0) {
  
               try {
                   Object ob=send.getText();
                  out.writeObject(ob);
                  SwingUtilities.invokeLater(new Runnable(){
  
                      public void run() {
                              ta.setText(ta.getText()+"\nYou:"+send.getText());
  
                          }
  
                      });
              } catch (IOException e1) {
                  e1.printStackTrace();
              }
  
                if (send.getText().equals("Bye"))
  
                       try {
                          so.close();
                          ss.close();
                          frame.dispose();
                      } catch (IOException e) {
                          e.printStackTrace();
                      }
  
          }
      });
  
  
       /////set Input///
       ObjectInputStream in = new ObjectInputStream(so.getInputStream());
       String ob ;
       while(true){
       try {
  
           ob = (String) in.readObject();
          if(ob!=null){
              ta.setText(ta.getText()+"\nClient:"+ob);
              }
      } catch (ClassNotFoundException e) {
          e.printStackTrace();
      }
       }
  
  
  
  
  
  } catch (IOException e) {
      e.printStackTrace();
  }
  
   }
  
  
  
  
  
  public static void main(String[] args) {
  
                  new ServerSide();
  
      }
      }
  </code></pre>
  
  <p>exception:</p>
  
  <pre><code>    java.net.ConnectException: Connection timed out: connect
      at java.net.DualStackPlainSocketImpl.connect0(Native Method)
      at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
      at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
      at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
      at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
      at java.net.PlainSocketImpl.connect(Unknown Source)
      at java.net.SocksSocketImpl.connect(Unknown Source)
      at java.net.Socket.connect(Unknown Source)
      at java.net.Socket.connect(Unknown Source)
      at java.net.Socket.&lt;init&gt;(Unknown Source)
      at java.net.Socket.&lt;init&gt;(Unknown Source)
      at ControlMouseProject.ClientSide.&lt;init&gt;(ClientSide.java:41)
      at ControlMouseProject.ClientSide.main(ClientSide.java:104)
  
  line 41:
       client=new Socket("IP",8080);
  </code></pre>