hello everybody..

i wrote java code in eclipse to create a simple apllication to send textbox 
content to c# application..

this is my code please

package com.example.clientsideand;

import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.Socket;
import java.net.UnknownHostException;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class MainActivity extends Activity {

Button b;
EditText et;
TextView tv;
private Socket socket;
int PORT = 4003;
String HOST = "10.0.2.2";
private Handler textview_handler_thread;
class ClientThread implements Runnable {
@Override
public void run()
{
try {
socket = new Socket(HOST, PORT);

BufferedReader in = new BufferedReader(new 
InputStreamReader(socket.getInputStream()));

String server_response_str;  

Message msg = null;
while(true) {      
msg = textview_handler_thread.obtainMessage();
String temp = in.readLine();
msg.obj = "Process Completed Succesfully";
textview_handler_thread.sendMessage(msg);
} 
}
catch (Exception e){
e.printStackTrace();
} 
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
b = (Button) findViewById(R.id.button1);
et = (EditText) findViewById(R.id.editText1);
new Thread(new ClientThread()).start();

textview_handler_thread = new Handler() {
       public void handleMessage(Message msg) {
           Object o = msg.obj;
           
           if (o == null) 
            o = "";
           
           TextView tv = (TextView)findViewById(R.id.textView1);
           tv.setText(o.toString());
       }
    };
b.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
try {
String input_str; 
String server_response_str;  
DataOutputStream output_to_server = new 
DataOutputStream(socket.getOutputStream());
String client_str = et.getText().toString();
output_to_server.writeBytes(client_str);
output_to_server.flush();
} catch (Exception e) {
e.printStackTrace();
}
}
});
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}

}


the layout file 

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android";
    xmlns:tools="http://schemas.android.com/tools";
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/button1"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="38dp" />

    <EditText
        android:id="@+id/editText1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="86dp"
        android:ems="10" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/editText1"
        android:layout_alignParentTop="true"
        android:layout_marginTop="40dp"
        android:text="Command"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/editText1"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="105dp"
        android:text="Delegate" />

</RelativeLayout>


the problem is No connection recived in c# side !!
what is the wrong thing in my code please?
i cant test the code in the emulator, my android application did not appear 
in the emulator !!
So i just test my application using android device ...


thanks in advanced..

-- 
You received this message because you are subscribed to the Google Groups 
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/android-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/android-developers/04a10a25-5fb2-4b64-8e5c-7b1701b73b15%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to