Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Help Needed - Strings from sockets?

  1. #1
    Junior Member
    Join Date
    Jan 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Help Needed - Strings from sockets?

    I'm able to send strings through sockets with a pc server and android client, but theres an issue.
    I use this
    output = new PrintWriter(MyClient.getOutputStream(), true);
    to send data from client and from server(MyClient changes between the two.)
    and this
    input = new BufferedReader(new InputStreamReader(MyClient.getInputStream()));
    to get data from the client and from the server(MyClient, again, changes.)
    but on the server, when i get the input and try to actually use it, such as
    	String in = input.readLine();
    if(in == "example"){
    do something
    }
    but of course, nothing happens and it seems to just skip it, i'm thinking maybe it does something to the encoding, but i really have no idea. Any ideas?


  2. #2
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 287 Times in 225 Posts
    Blog Entries
    4

    Default Re: Help Needed - Strings from sockets?

    Hello nate0927,

    Welcome to the Java Programming Forums.

    This is a very simple mistake,

    You need to change the code to:

    String in = input.readLine();
    if(in.equals("example")){
    do something
    }

    Please read - http://www.javaprogrammingforums.com...-mistakes.html
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

    Looking for a Java job? Visit - Java Programming Careers

Similar Threads

  1. Java sockets help
    By ma05k1 in forum Java Theory & Questions
    Replies: 1
    Last Post: March 27th, 2010, 05:52 AM
  2. Replies: 1
    Last Post: March 23rd, 2010, 02:29 AM
  3. Replies: 1
    Last Post: December 2nd, 2009, 03:01 AM
  4. Strings
    By Leeds_Champion in forum Algorithms & Recursion
    Replies: 3
    Last Post: November 3rd, 2009, 09:09 PM
  5. Replies: 1
    Last Post: October 20th, 2009, 06:31 AM