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.


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
    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
    United Kingdom
    My Mood
    Thanked 293 Times in 226 Posts
    Blog Entries

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

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, 04:01 AM
  4. Strings
    By Leeds_Champion in forum Algorithms & Recursion
    Replies: 3
    Last Post: November 3rd, 2009, 10:09 PM
  5. Replies: 1
    Last Post: October 20th, 2009, 06:31 AM