i think your problem is the ip address..127.0.0.1 is the device/ emulator itself not the machine on which you are programming...if you need to call localhost u should try this address-->10.0.2.2
read this too-->http://developer.android.com/guide/appendix/faq/ Regards Gino On Jan 22, 12:44 pm, saikiran n <saikiran....@gmail.com> wrote: > Hi > I have done socket communication in a single application it is working fine > But my requirement is i have opened two emulators and i am able to send sms > between those two. > Now i want to run server in one emulator(myavd-5554) > and client on another emulator(myavd1-5556) > I have used the following code > on Serverside > public class TCPServerActivity extends Activity { > /** Called when the activity is first created. */ > @Override > public void onCreate(Bundle savedInstanceState) { > super.onCreate(savedInstanceState); > setContentView(R.layout.main); > Thread sThread = new Thread(new TCPServer()); > sThread.start(); > try { > Thread.sleep(90000); > } catch (InterruptedException e) { > // TODO Auto-generated catch block > e.printStackTrace(); > } > Log.d("","Server activity closed"); > } > > } > > public class TCPServer implements Runnable{ > > public static final String SERVERIP = "127.0.0.1"; > public static final int SERVERPORT = 3000; > > public void run() { > try { > Log.d("TCP", "S: Connecting..."); > > ServerSocket serverSocket = new ServerSocket(SERVERPORT); > while (true) { > Socket client = serverSocket.accept(); > Log.d("TCP", "S: Receiving..."); > try { > BufferedReader in = new BufferedReader(new > InputStreamReader(client.getInputStream())); > String str = in.readLine(); > Log.d("TCP", "S: Received: '" + str + "'"); > > } catch(Exception e) { > Log.e("TCP", "S: Error", e); > } finally { > client.close(); > Log.d("TCP", "S: Done."); > } > > } > > } catch (Exception e) { > Log.e("TCP", "S: Error", e); > } > } > > } > > on client side > public class TCPClientActivity extends Activity { > /** Called when the activity is first created. */ > @Override > public void onCreate(Bundle savedInstanceState) { > super.onCreate(savedInstanceState); > setContentView(R.layout.main); > Thread cThread = new Thread(new TCPClient()); > cThread.start(); > > Log.d("","Client activity closed"); > > } > > } > > public class TCPClient implements Runnable { > > public static final String SERVERIP = "127.0.0.1"; > public static final int SERVERPORT = 3000; > > public void run() { > try { > > InetAddress serverAddr = InetAddress.getByName(SERVERIP); > > Log.d("TCP", "C: Connecting..."); > Socket socket = new Socket(serverAddr, SERVERPORT); > String message = "Hello from Client"; > try { > Log.d("TCP", "C: Sending: '" + message + "'"); > PrintWriter out = new PrintWriter( new BufferedWriter( new > OutputStreamWriter(socket.getOutputStream())),true); > > out.println(message); > Log.d("TCP", "C: Sent."); > Log.d("TCP", "C: Done."); > > } catch(Exception e) { > Log.e("TCP", "S: Error", e); > } finally { > socket.close(); > } > } catch (Exception e) { > Log.e("TCP", "C: Error", e); > } > } > > } > > So i run Server application on 5554 first and then client application on > 5556 > But i didn't receved the message > Please help me > 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