title: TCP/IP on Android
body: <p>I have an android application which I want to send a simple command to my `public class ActivitymainActivity extends Activity {</p>
  
  <pre><code>private TextView textview;
  private Button button;
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activitymain);
  
      textview=(TextView) findViewById(R.id.EmailCount);
      button=(Button) findViewById(R.id.button1);
      textview.setText("Going in");
      try{
          Socket socket = new Socket("192.168.1.66", 2727);   
  
          OutputStream out = socket.getOutputStream();       
          PrintWriter output = new PrintWriter(out);         
  
          textview.setText("Sending Data to PC");         
          output.println("Hello from Android");
          output.flush();
          output.close();
          textview.setText("Data sent to PC");            
  
          socket.close();                                    
          textview.setText("Socket closed"); 
      }
      catch(Exception e){System.out.print(e+"shacso");}
  
      button.setOnClickListener(new View.OnClickListener() {
  
          @Override
          public void onClick(View v) {
              // TODO Auto-generated method stub
              textview.setText("Trying to send");
               try{
                      Socket socket = new Socket("192.168.1.66", 2727);   
  
                      OutputStream out = socket.getOutputStream();       
                      PrintWriter output = new PrintWriter(out);         
  
                      textview.setText("Sending Data to PC");         
                      output.println("Checking Email now:D");
                      output.flush();
                      output.close();
                      textview.setText("Data sent to PC");            
  
                      socket.close();                                    
                      textview.setText("Socket closed");                  }
                  catch(Exception e){System.out.print(e+"");}
  
          }
      });
  }
  
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
      getMenuInflater().inflate(R.menu.activitymain, menu);
      return true;
  }
  </code></pre>
  
  <p>}
  `</p>
  
  <p>And this is my Manifest:</p>
  
  <pre><code>&lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="com.example.emailclient"
  android:versionCode="1"
  android:versionName="1.0" &gt;
  
  &lt;uses-sdk
      android:minSdkVersion="8"
      android:targetSdkVersion="15" /&gt;
  &lt;uses-permission android:name="android.permission.INTERNET"&gt;&lt;/uses-permission&gt;
  
  &lt;application
      android:icon="@drawable/ic_launcher"
      android:label="@string/app_name"
      android:theme="@style/AppTheme" &gt;
      &lt;activity
          android:name=".ActivitymainActivity"
          android:label="@string/title_activity_activitymain" &gt;
          &lt;intent-filter&gt;
              &lt;action android:name="android.intent.action.MAIN" /&gt;
  
              &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
          &lt;/intent-filter&gt;
      &lt;/activity&gt;
  &lt;/application&gt;
  </code></pre>
  
  <p></p>
  
  <p>However, I am not able to receive anything on the server. Downloaded an application from play store called "UDP TCP Server" it send packets to a specified Ip and port and I was able to get the sent data to my server. Anything wrong with my code?</p>
  
  <p>Code explanation: Send data went app lunches and when a button on clicked</p>
  
  <p>Thanks :)</p>