package com.in2em.clientactivity;

import java.io.BufferedWriter;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.InetAddress;
import java.net.Socket;

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

public class ClientActivity extends Activity {
    /** Called when the activity is first created. */
     private EditText serverIp;

        private Button connectPhones;

        private String serverIpAddress = "192.168.1.27";

        private boolean connected = false;

        private Handler handler = new Handler();

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.client);

           // serverIp = (EditText) findViewById(R.id.server_ip);
            connectPhones = (Button) findViewById(R.id.connect_phones);

connectPhones.setOnClickListener((android.view.View.OnClickListener)
connectListener);
        }

        private OnClickListener connectListener = new OnClickListener() {

            @Override
            public void onClick(View v) {
                if (!connected) {
                  //  serverIpAddress = serverIp.getText().toString();
                  //  if (!serverIpAddress.equals("")) {
                        Thread cThread = new Thread(new ClientThread());
                        cThread.start();
                   // }
                }
            }
        };

        public class ClientThread implements Runnable {

            public void run() {
                try {
                    InetAddress serverAddr =
InetAddress.getByName(serverIpAddress);
                    Log.d("ClientActivity", "C: Connecting...");
                    Socket socket = new Socket(serverAddr, 9999);

                    while (connected) {

                        try {
                            Log.d("ClientActivity", "C: Sending command.");
                            PrintWriter out = new PrintWriter(new
BufferedWriter(new OutputStreamWriter(socket
                                        .getOutputStream())), true);
                                // where you issue the commands
                                out.println("Hey Server!");
                                Log.d("ClientActivity", "C: Sent.");
                        } catch (Exception e) {
                            Log.e("ClientActivity", "S: Error", e);
                        }
                    }
                    socket.close();
                    Log.d("ClientActivity", "C: Closed.");
                } catch (Exception e) {
                    Log.e("ClientActivity", "C: Error", e);
                    connected = false;
                }
            }
        }
}

On 21 June 2013 18:15, Ibrahim Sada <ibrahim.in...@gmail.com> wrote:

> if u want i can send u my code...
>
>
> On 21 June 2013 17:58, Kristopher Micinski <krismicin...@gmail.com> wrote:
>
>> Please talk in more understandable English :-),
>>
>> What specifically are you having trouble with? There's no special
>> function you have to call on Android that makes things "magically
>> work."
>>
>> Kris
>>
>> On Fri, Jun 21, 2013 at 8:18 AM, Ibrahim Sada <ibrahim.in...@gmail.com>
>> wrote:
>> > I used bro..i can do java server client properly..bt i cant do server as
>> > java and android as client....
>> > i cant do yaar
>> >
>> >
>> > On 21 June 2013 17:36, Kristopher Micinski <krismicin...@gmail.com>
>> wrote:
>> >>
>> >> You should just be able to use any Java sockets tutorial, that isn't
>> >> the hard part,
>> >>
>> >> Kris
>> >>
>> >> On Fri, Jun 21, 2013 at 6:53 AM, Ibrahim Sada <ibrahim.in...@gmail.com
>> >
>> >> wrote:
>> >> > Hi Friends I Want To Connect Server As Pc And Client As Android
>> >> > device(emulator)
>> >> > After connecting i want to sends and recive mesgs from eachothers..
>> >> > I Am not able to do so..
>> >> > Please Help me put friends please
>> >> > Thanks...In Advance
>> >> >
>> >> > --
>> >> > --
>> >> > You received this message because you are subscribed to the Google
>> >> > Groups "Android Developers" group.
>> >> > To post to this group, send email to
>> android-developers@googlegroups.com
>> >> > To unsubscribe from this group, send email to
>> >> > android-developers+unsubscr...@googlegroups.com
>> >> > For more options, visit this group at
>> >> > http://groups.google.com/group/android-developers?hl=en
>> >> > ---
>> >> > 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 android-developers+unsubscr...@googlegroups.com.
>> >> > For more options, visit https://groups.google.com/groups/opt_out.
>> >> >
>> >> >
>> >>
>> >> --
>> >> --
>> >> You received this message because you are subscribed to the Google
>> >> Groups "Android Developers" group.
>> >> To post to this group, send email to
>> android-developers@googlegroups.com
>> >> To unsubscribe from this group, send email to
>> >> android-developers+unsubscr...@googlegroups.com
>> >> For more options, visit this group at
>> >> http://groups.google.com/group/android-developers?hl=en
>> >> ---
>> >> 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 android-developers+unsubscr...@googlegroups.com.
>> >> For more options, visit https://groups.google.com/groups/opt_out.
>> >>
>> >>
>> >
>> > --
>> > --
>> > You received this message because you are subscribed to the Google
>> > Groups "Android Developers" group.
>> > To post to this group, send email to
>> android-developers@googlegroups.com
>> > To unsubscribe from this group, send email to
>> > android-developers+unsubscr...@googlegroups.com
>> > For more options, visit this group at
>> > http://groups.google.com/group/android-developers?hl=en
>> > ---
>> > 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 android-developers+unsubscr...@googlegroups.com.
>> > For more options, visit https://groups.google.com/groups/opt_out.
>> >
>> >
>>
>> --
>> --
>> You received this message because you are subscribed to the Google
>> Groups "Android Developers" group.
>> To post to this group, send email to android-developers@googlegroups.com
>> To unsubscribe from this group, send email to
>> android-developers+unsubscr...@googlegroups.com
>> For more options, visit this group at
>> http://groups.google.com/group/android-developers?hl=en
>> ---
>> 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 android-developers+unsubscr...@googlegroups.com.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>>
>>
>

-- 
-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
--- 
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 android-developers+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to