Ibrahim wrote:

> Friends I Am trying to connect server on pc and client on android device..
>

Warning: I am not your friend.
 

> My server is working fine...
> but my client is not working ...
> Here is my sever and client code...
>
> Server Code...
>
>
> public class Server_tcp {
>

Please follow the Java naming conventions.
 

>      void run(){
>

Why is this method not public?
 

>             {
>                 try {
>                     System.out.println("Hi Im In 1st Try");
>                     try {
>                         System.out.println("Hi Im In 2nd try ");
>                         Boolean end = false;
>

Why did you declare this 'Boolean' and not 'boolean'?
 

>                         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");
>

Calls to 'System.out.println()' are the worst of the available logging 
options.
 

>                             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();
>

Why do you flush an auto-flushed stream?
 

>                             
>                             s.close();
>                             if (st==null){ end = true; }
>                         }
>                         ss.close();
>                     } catch (UnknownHostException e) {
>                         // TODO Auto-generated catch block
>                         e.printStackTrace();
>

Handle errors, don't ignore them.
 

>                     }
>                 } 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();
>

So you restart the server every time you choose to close it. Hmm.
 

>             }
>         }
>
> }
>
>
>
> 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();
>

Please follow the Java naming conventions.
 

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

What does that mean? 

In other words, what did you expect, and what happened instead?

Copy and paste messages; do not paraphrase them.
 

> Can Any One help me ???
>

You only need one question mark at the end of an interrogative sentence.

And no, not without sufficient information.

-- 
Lew
 

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