Please refer to this thread, it can work.
http://groups.google.com/group/android-developers/browse_thread/thread/16f5948d7bf2e1a5/c53c2c1a4a1c4a5f?hl=en&lnk=gst&q=ServerSocket#c53c2c1a4a1c4a5f
On May 8, 4:05 pm, Gibson <[EMAIL PROTECTED]> wrote:
> Hi all,
> I got a problem about using ServerSocket on emulator. I just try
> to set up a ServerSocket on emulator and create a client on Windows to
> connect to the server on Emulator. I tried adb forward the port and
> also redir the port. But all failed. Anyone has succeeded doing this?
> Any piece of code is welcome.
> Thanks very much!
>
> server part:
>
> try {
> ServerSocket ssocket = new ServerSocket(22266);
> Log.v("tag", "port:" + ssocket.getLocalPort());
> Log.v("tag", "" + "start");
> Socket socket = ssocket.accept();
> Log.v("tag", "" + "ok");
> System.out.println(socket.getRemoteSocketAddress());
> InputStream in = socket.getInputStream();
> OutputStream out = socket.getOutputStream();
> DataInputStream din = new DataInputStream(in);
> String str = din.readUTF();
> Log.v("tag", "got string:" + str);
> in.close();
> out.close();
> } catch (IOException e) {
> e.printStackTrace();
> }
>
> client part:
> try {
> Socket socket = new Socket("10.15.6.129",22266);
> OutputStream out = socket.getOutputStream();
> DataOutputStream dout = new DataOutputStream(out);
> dout.writeUTF("hello world");
> dout.close();
> socket.close();
> } catch (UnknownHostException e) {
> e.printStackTrace();
> } catch (IOException e) {
> e.printStackTrace();
> }
>
> BR
> Gi
bson
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
Announcing the new M5 SDK!
http://android-developers.blogspot.com/2008/02/android-sdk-m5-rc14-now-available.html
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---