Results 1 to 12 of 12
  1. #1
    lilezek is offline Member
    Join Date
    Jun 2012
    Posts
    23
    Rep Power
    0

    Default Java problems with encodings.

    I'm a Linux user and I'm working with Java from Linux. So I did a two programs, one acts as client, and other acts as server.

    The problem began when the client was executed from Windows. So, if I have this code at client (windows):

    Java Code:
    sockout.write(userNameBox.getText()+'\n');
    sockout.write(new String(passwordBox.getPassword())+'\n');
    Being userNameBox : JTextField and passwordBox : JPasswordField, and I type in those:

    'User'
    'Contraseña' (spanish word for password)

    Linux server recive two lines with:

    'User'
    'Contrase�a'

    Any idea?

    Regards.

  2. #2
    lilezek is offline Member
    Join Date
    Jun 2012
    Posts
    23
    Rep Power
    0

    Default Re: Java problems with encodings.

    I thought this is an easy problem :(

    Does none know how to help me? If I didn't explained the problem as good as necessary, just tell it.

  3. #3
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,421
    Rep Power
    25

    Default Re: Java problems with encodings.

    What does the server receive when the client sends those two lines?
    Can you explain what the problem is?
    If you don't understand my response, don't ignore it, ask a question.

  4. #4
    lilezek is offline Member
    Join Date
    Jun 2012
    Posts
    23
    Rep Power
    0

    Default Re: Java problems with encodings.

    Quote Originally Posted by lilezek View Post
    Being userNameBox : JTextField and passwordBox : JPasswordField, and I type in those:

    'User'
    'Contraseña' (spanish word for password)

    Linux server recive two lines with:

    'User'
    'Contrase�a'
    The problem is that 'ñ' in windows is '�' in linux (encoding problem).

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,014
    Rep Power
    20

    Default Re: Java problems with encodings.

    It's quite possible that the thing you are using to display what has arrived at the server is unable to handle that character.
    Of course we do not know how you are doing this.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  6. #6
    lilezek is offline Member
    Join Date
    Jun 2012
    Posts
    23
    Rep Power
    0

    Default Re: Java problems with encodings.

    Okay, I'm going to try to explain again.

    I've done an application, that is running on Windows (when I run it in Linux it works perfectly and this error never happens). This application shows a JFrame containing these components:

    userNameBox : JTextField and passwordBox : JPasswordField

    So, when (in Windows) I type in userNameBox 'User' and in passwordBox 'Contraseña', my program does:

    Java Code:
    sockout.write(userNameBox.getText()+'\n');
    sockout.write(new String(passwordBox.getPassword())+'\n');
    sockout.flush();
    Where sockout is a BufferedWriter binded to a client socket connected to my server (that is running Linux).

    So, if in my server I run netcat to listen (to see what I'm receiving), netcat shows:

    'User'
    'Contrase?a'

    Where ? is a weird character. So I thought this is something relationed with encondings.

    Does it now make sense? If not, ask me and I'll try to explain better...

  7. #7
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,421
    Rep Power
    25

    Default Re: Java problems with encodings.

    Several constructors have parameters for encoding. Try setting the encoding in some of them. We'd need a test program to see what will work.
    If you don't understand my response, don't ignore it, ask a question.

  8. #8
    lilezek is offline Member
    Join Date
    Jun 2012
    Posts
    23
    Rep Power
    0

    Default Re: Java problems with encodings.

    What constructor do you refer?

    String have String(byte[], Charset), but JPasswordField#getPassword() returns char[], not byte[]

    So I don't get you.

  9. #9
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,421
    Rep Power
    25

    Default Re: Java problems with encodings.

    Look at the constructors for the classes in the io package.
    If you don't understand my response, don't ignore it, ask a question.

  10. #10
    lilezek is offline Member
    Join Date
    Jun 2012
    Posts
    23
    Rep Power
    0

    Default Re: Java problems with encodings.

    I think you're right. Gonna try, and thank you for your patience.

  11. #11
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,421
    Rep Power
    25

    Default Re: Java problems with encodings.

    Good luck. Hard to test on one machine with one OS.
    If you don't understand my response, don't ignore it, ask a question.

  12. #12
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,014
    Rep Power
    20

    Default Re: Java problems with encodings.

    Quote Originally Posted by lilezek View Post
    Okay, I'm going to try to explain again.

    I've done an application, that is running on Windows (when I run it in Linux it works perfectly and this error never happens). This application shows a JFrame containing these components:

    userNameBox : JTextField and passwordBox : JPasswordField

    So, when (in Windows) I type in userNameBox 'User' and in passwordBox 'Contraseña', my program does:

    Java Code:
    sockout.write(userNameBox.getText()+'\n');
    sockout.write(new String(passwordBox.getPassword())+'\n');
    sockout.flush();
    Where sockout is a BufferedWriter binded to a client socket connected to my server (that is running Linux).

    So, if in my server I run netcat to listen (to see what I'm receiving), netcat shows:

    'User'
    'Contrase?a'

    Where ? is a weird character. So I thought this is something relationed with encondings.

    Does it now make sense? If not, ask me and I'll try to explain better...
    I got that, but I would first off look at the actual bytes you are receiving on the server, not the text as translated by netcat.
    If those bytes match (eg) the unicode for all the characters then your client is sending the correct stuff.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Problem with String encodings
    By sandeepsai39 in forum New To Java
    Replies: 7
    Last Post: 05-24-2011, 12:02 PM
  2. Java RPG problems
    By Nickmanzz in forum New To Java
    Replies: 13
    Last Post: 04-13-2011, 09:14 PM
  3. java problems
    By swrta in forum AWT / Swing
    Replies: 1
    Last Post: 03-23-2011, 01:32 PM
  4. Replies: 2
    Last Post: 01-16-2010, 04:50 PM
  5. File encodings
    By JL4 in forum New To Java
    Replies: 3
    Last Post: 11-23-2008, 05:09 PM

Posting Permissions

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