Based on your client and server code, which is found here (copied
wholesale):

http://stackoverflow.com/questions/8045796/server-client-android-to-pc-communication-issue

I think I can guess what u are looking for.   You are looking for  a piece
of code that run on the "server", which in your case is your PC, and an
android Apps as the client.   Correct?

First, if u identify your PC IP address, and go to your Android device (via
adb), and ping back at the PC IP, you can see that potentially they can
talk.

So setting up the client and server is very much like normal TCP/IPsocket
programming:

PC:  running Java applet as TCP server.
Android:   your activity running as TCP client.

My suggestion is that you should try a simple client-server on the PC first
to familiarize with Java:

http://systembash.com/content/a-simple-java-tcp-server-and-tcp-client/

Thanks.

On Fri, Jun 21, 2013 at 8:46 PM, Ibrahim Sada <ibrahim.in...@gmail.com>wrote:

> package com.in2em.server;
>
> import java.io.BufferedReader;
> import java.io.IOException;
> import java.io.InputStreamReader;
> import java.io.PrintStream;
> import java.net.InetAddress;
> import java.net.ServerSocket;
> import java.net.Socket;
>
> public class Server {
>     public static void main(String[] args) {
>
>         try {
>             // First we create a server socket and bind it to port 9999.
>             ServerSocket myServerSocket = new ServerSocket(9999);
>
>
>             // wait for an incoming connection...
>             System.out.println("Server is waiting for an incoming
> connection on host="
>                     + InetAddress.getLocalHost().getCanonicalHostName()
>                     + " port=" + myServerSocket.getLocalPort());
>             Socket skt = myServerSocket.accept();
>
>             // ok, got a connection.  Let's use java.io.* niceties to read
> and write from the connection.
>             BufferedReader myInput = new BufferedReader(new
> InputStreamReader(skt.getInputStream()));
>             PrintStream myOutput = new
> PrintStream(skt.getOutputStream());
>
>             // attempt to read input from the stream.
>             String buf = myInput.readLine();
>
>             // if we got input, print it out and write a message back to
> the remote client..
>             if (buf != null) {
>                 System.out.println("Server read: [" + buf + "]");
>                 myOutput.print("got it");
>             }
>
>             // close the connection.
>             skt.close();
>             System.out.println("Server is exiting");
>
>         } catch (IOException ex) {
>             ex.printStackTrace();
>             System.out.println("Whoops, something bad happened!  I'm outta
> here.");
>
>         }
>
>
>
>     }
>
> }
>
>
> On 21 June 2013 18:16, Ibrahim Sada <ibrahim.in...@gmail.com> wrote:
>
>> 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.
>
>
>



-- 
Regards,
Peter Teoh

-- 
-- 
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