Instead of
if (test != "end")
do
if (test.equals("end"))
Look at the link about string comparison
http://leepoint.net/notes-java/data/strings/12stringcomparison.html
--
Roman Baumgaertner
Sr. SW Engineer-OSDC
·T· · ·Mobile· stick together
The views, opinions and statements in this email are those of the
author solely in their individual capacity, and do not necessarily
represent those of T-Mobile USA, Inc.
On Jul 23, 5:35 am, Lordsaibat <[email protected]> wrote:
> Java:
>
> public void server()
> {
> DataOutputStream os=null;
> DataInputStream is = null;
> ServerSocket socket = null;
> Socket ClientSocket = null;
> String out = null;
> try
> {
> socket = new ServerSocket(SERVERPORT);//10.0.2.2
>
> if(socket == null)
> {
> Log.d("TagServer()", "socket null");
> }
> else
> {
> Log.d("TagServer()", "Waiting...");
> ClientSocket = socket.accept();
> os = new DataOutputStream
> (ClientSocket.getOutputStream());
> is = new DataInputStream
> (ClientSocket.getInputStream());
> /* By magic we know, how much data will be
> waiting for us*/
> byte[] buf = new byte[100];
> int readLen = 0;
> boolean listening = true;
>
> while(listening == true)
> //while((out != "end") || (readLen = is.read(buf,
> 0, 100)) != -1)
> //while (out != "end")
> {
>
> if ((readLen = is.read(buf, 0, 100)) != -1){
> out = new String(buf, 0, readLen-1);
> Log.d("TCP", out);
> os.writeBytes("gotit");
>
> String test = out.toString();
>
> if (test != "end")
> {
> listening = true;
> }else{
> listening = false;
> }
> }
>
> }
> os.close();
> is.close();
> socket.close();
> ClientSocket.close();
> Log.d("TagServer()", "Finished");
> }
> }
> catch(Exception e)
> {
> System.out.println(e);
> Log.d("TagServer()", e.toString());
> }
> }
>
> Ok I am trying to be able to stop listening for packets and I am
> trying to do that with the test variable.
> no matter what it seems that test never = ends.
>
> Any ideas?
--~--~---------~--~----~------------~-------~--~----~
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]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---