Friends I Am trying to connect server on pc and client on android device.. My server is working fine... but my client is not working ... Here is my sever and client code...
Server Code... public class Server_tcp { void run(){ { try { System.out.println("Hi Im In 1st Try"); try { System.out.println("Hi Im In 2nd try "); Boolean end = false; ServerSocket ss = new ServerSocket(4444); System.out.println("socket created"); while(!end){ //Server is waiting for client here, if needed Socket s = ss.accept(); System.out.println("socket accepted"); BufferedReader input = new BufferedReader(new InputStreamReader(s.getInputStream())); PrintWriter output = new PrintWriter(s.getOutputStream(),true); //Autoflush String st = input.readLine(); System.out.println("Tcp Example" + "From client: "+st); output.println("I got the Message:)"); output.flush(); s.close(); if (st==null){ end = true; } } ss.close(); } catch (UnknownHostException e) { // TODO Auto-generated catch block e.printStackTrace(); } } catch (IOException exp) { // TODO Auto-generated catch block exp.printStackTrace(); } } } public static void main(String args[]) { Server_tcp server = new Server_tcp(); while(true){ server.run(); } } } Client Code.... public class ClientTCPActivity extends Activity { /** Called when the activity is first created. */ private EditText et; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); System.out.println("Before try net"); Run(); System.out.println("after try net"); } public void Run() { System.out.println("inside try net"); try { System.out.println("inside try"); Socket s = new Socket("192.168.1.27",4444); //outgoing stream redirect to socket // OutputStream out = (OutputStream) et.getContentDescription(); PrintWriter output = new PrintWriter(s.getOutputStream(),true); output.println("Hello Android!"); BufferedReader input = new BufferedReader(new InputStreamReader(s.getInputStream())); //read line(s) String st = input.readLine(); System.out.println(st); //Close connection s.close(); System.out.println(" try "); } catch (UnknownHostException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } My Client is not working properly my friends.... Can Any One 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 --- 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.