title: Android:: socket communication between pc and phone over wifi?
body: <p>I have a working code in which i can exchange data between pc and android emulator. Now, I want to test this application with a real android device. i.e i want to exchange text between my pc in which i have a java server and the android phone. For my emulator i was using the emulator virtual ip address and it was working fine. But, to test my application in phone I connected the phone and pc in same network and used the ip address of the phone in my application. Then I installed the application in phone but the connection did not established. How other changes is to be done in code to use this application in phone. Here, is my android code, </p>
  
  <pre><code>try {
          client = new Socket("123.236.165.50", 9999);
          printwriter = new PrintWriter(client.getOutputStream(), true);
          printwriter.println(messsage[0] + "\n");
          System.out.println("messsage::"+messsage[0]);
          printwriter.flush();
          BufferedReader in = new BufferedReader(new InputStreamReader(client.getInputStream()));
  
                  serverMessage = in.readLine();
                  if (serverMessage.equals("exit")) {
                      runOnUiThread(new Runnable() {
                          public void run() {
                              tv.setText("Thankyu visit again!!" + "\n");
                          }
                      });                     }   
                  else {
                  runOnUiThread(new Runnable() {
                      public void run() {
                          tv.setText(serverMessage.toString() + "\n");
                      }
                  });
  
          }
       }
      } catch (UnknownHostException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      } catch (IOException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      }
  
      return null;
  </code></pre>
  
  <p>Also, i have given this permission in my manifest file:</p>
  
  <pre><code>&lt;uses-permission android:name="android.permission.INTERNET"/&gt;
    &lt;uses-permission android:name="android.permission.ACCESS_WIFI_STATE"&gt;&lt;/uses-permission&gt;
    &lt;uses-permission android:name="android.permission.CHANGE_WIFI_STATE"&gt;&lt;/uses-permission&gt;
  </code></pre>
  
  <p>This is my first android app, So please help!!!</p>