title: Android socket connection refused error
body: <p>I want to implement socket connection between 2 deceives , client keep sending GPS data to the server and  I need both of it run in new thread , the client send first one data then keep show error like this </p>
  
  <blockquote>
    <p>03-18 16:35:11.805: E/Client run:(8163): java.net.ConnectException: failed to connect to /192.168.2.103 (port 5678): connect failed: ECONNREFUSED (Connection refused)</p>
  </blockquote>
  
  <p>here is the client code </p>
  
  <pre><code>    public class Send implements Runnable{
  
      private boolean Connect = true;
  
      public void Connect(){
          Connect = true;
      }
      public void Disconnect(){
          Connect = false;
      }
  
      @Override
      public void run() {
          // TODO Auto-generated method stub
          while(Connect){
              try {
                  SocketClient = new Socket("192.168.2.103", 5678);
                  ObjectOutputStream oos = new ObjectOutputStream(SocketClient.getOutputStream());
                  oos.writeDouble(GPSinfo[2]);
                  //ObjectInputStream ois = new ObjectInputStream(SocketClient.getInputStream());
                  //ois.readInt();
                  oos.close();
                  //ois.close();
              } catch (Exception e) {
                  Log.e("Client run: ", e.toString());
              }
          }
  
      }
  
  }
  </code></pre>
  
  <p>here is server code </p>
  
  <pre><code>    public class Receive implements Runnable{
      private boolean CanReceive = true;
      private double Data;
  
      public void Connect(){
          CanReceive = true;
      }
      public void Disconnect(){
          CanReceive = false;
      }
  
      @Override
      public void run() {
          // TODO Auto-generated method stub
  
          while(CanReceive){
              try {
                  SocketServer = new ServerSocket(5678);
                  Socket connectedSocket = SocketServer.accept();
                  ObjectInputStream ois = new ObjectInputStream(connectedSocket.getInputStream());
                  Data = ois.readDouble();
                  DataText.setText("" + Data);
                  //ObjectOutputStream oos = new ObjectOutputStream(connectedSocket.getOutputStream());
                  //oos.writeInt(1);
                  //ois.close();
                  //oos.close();
              } catch (Exception e) {
                  Log.e("Server run: ", e.toString());
              }
  
          }
      }
  
  }
  </code></pre>
  
  <p>by the way , the both code is inner class , and INTERNET permission is added.</p>