Results 1 to 9 of 9
  1. #1
    Lionlev is offline Senior Member
    Join Date
    May 2012
    Posts
    172
    Rep Power
    2

    Question What is the meaning of the char(0x00)?

    Basically I've got a java server and a flash client
    On the java code the is a var "char EOF = (char)0x00;" and when it sends a message to the client the code looks like this:
    OUT.println("message what ever" + EOF);

    The client receives it like this: (printed in client's console)
    "message what ever


    "

    As you see there are multiple empty lines created.. I don't what that.. But when I remove the "+EOF" the client doesn't receive anything at all..

    Help?
    Last edited by Lionlev; 06-09-2012 at 10:06 PM.

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default Re: What is the meaning of the char(0x00)?

    The value zero represents the number of things you have of some type when things of that type are, in fact, completely absent. As such it is a rather abstract (peculiar?) number - but it has its uses.

    In Java code zero can be the value of any integral data type (long, int, char). Just a guess - without seeing any code - but it looks like zero is being sent to the client to mean "this is the end of the message".

    when I remove the "+EOF" the client doesn't receive anything at all.
    Are you sure about that? Why?

    More likely, the client receives the bytes OK. But you have removed the zero so the client never learns that "this is the end of the message", and, hence, never moves on to print the message.

    -----

    If you are new to Java (or programming) I would recommend being cautious about trying to hack about with existing, rather complex code. Learn the basics first, with code you design and write yourself. But who am I to say? - you know yourself best.

    In any case as well as the code, I find I usually need to know the general "approach" (what the author hopes to achieve) being used before I can make head or tail of individual lines. And the "architecture" - in this case what a client and server *are* and how, in code, they communicate. In short when reading other people's code - and especially in unfamiliar territory - the documentation surrounding the code is vital and is the starting place. Without that documentation, I wouldn't bother.

  3. #3
    Lionlev is offline Senior Member
    Join Date
    May 2012
    Posts
    172
    Rep Power
    2

    Default Re: What is the meaning of the char(0x00)?

    Quote Originally Posted by pbrockway2 View Post
    The value zero represents the number of things you have of some type when things of that type are, in fact, completely absent. As such it is a rather abstract (peculiar?) number - but it has its uses.

    In Java code zero can be the value of any integral data type (long, int, char). Just a guess - without seeing any code - but it looks like zero is being sent to the client to mean "this is the end of the message".



    Are you sure about that? Why?

    More likely, the client receives the bytes OK. But you have removed the zero so the client never learns that "this is the end of the message", and, hence, never moves on to print the message.

    -----

    If you are new to Java (or programming) I would recommend being cautious about trying to hack about with existing, rather complex code. Learn the basics first, with code you design and write yourself. But who am I to say? - you know yourself best.

    In any case as well as the code, I find I usually need to know the general "approach" (what the author hopes to achieve) being used before I can make head or tail of individual lines. And the "architecture" - in this case what a client and server *are* and how, in code, they communicate. In short when reading other people's code - and especially in unfamiliar territory - the documentation surrounding the code is vital and is the starting place. Without that documentation, I wouldn't bother.
    Ok... But I don't know why is there so many new lines created...

  4. #4
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,551
    Rep Power
    23

    Default Re: What is the meaning of the char(0x00)?

    What class is the OUT object? What does its println method do when it tries to print a char with a value of 0?
    If you don't understand my response, don't ignore it, ask a question.

  5. #5
    Lionlev is offline Senior Member
    Join Date
    May 2012
    Posts
    172
    Rep Power
    2

    Default Re: What is the meaning of the char(0x00)?

    Quote Originally Posted by Norm View Post
    What class is the OUT object? What does its println method do when it tries to print a char with a value of 0?
    That's a printwriter, OUT.println sends data to the flash client

  6. #6
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,551
    Rep Power
    23

    Default Re: What is the meaning of the char(0x00)?

    What does the client program do when it tries to display a String with a char = 0?
    If you don't understand my response, don't ignore it, ask a question.

  7. #7
    Lionlev is offline Senior Member
    Join Date
    May 2012
    Posts
    172
    Rep Power
    2

    Default Re: What is the meaning of the char(0x00)?

    Quote Originally Posted by Norm View Post
    What does the client program do when it tries to display a String with a char = 0?
    3 empty lines, let me correct my post
    I noticed that client's console prints it like this:
    "bla bla and only then it adds 2 more empty lines


    "

  8. #8
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,551
    Rep Power
    23

    Default Re: What is the meaning of the char(0x00)?

    I think every program can do something different when it prints a char = 0. Read the doc for the program or test the program with different char values to see what it does.
    Another example is the tab character, every program that prints a tab character can do something different with it.
    If you don't understand my response, don't ignore it, ask a question.

  9. #9
    Lionlev is offline Senior Member
    Join Date
    May 2012
    Posts
    172
    Rep Power
    2

    Default Re: What is the meaning of the char(0x00)?

    Quote Originally Posted by Norm View Post
    I think every program can do something different when it prints a char = 0. Read the doc for the program or test the program with different char values to see what it does.
    Another example is the tab character, every program that prints a tab character can do something different with it.
    Oh ok, I'll try.. Thanks

Similar Threads

  1. check a string char by char
    By Sotsiak in forum New To Java
    Replies: 2
    Last Post: 10-23-2010, 09:24 PM
  2. replaceALL(char oldChar, char newChar) method
    By arson09 in forum New To Java
    Replies: 0
    Last Post: 04-28-2010, 05:48 AM
  3. for loop meaning
    By ahmakki in forum New To Java
    Replies: 3
    Last Post: 04-12-2010, 01:06 AM
  4. drawing char by char with Graphics
    By diggitydoggz in forum New To Java
    Replies: 5
    Last Post: 12-27-2008, 12:49 PM
  5. Exception:Meaning
    By tiger100plus in forum New To Java
    Replies: 2
    Last Post: 11-27-2008, 07:45 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •