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):
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.
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.
Re: Java problems with encodings.
What does the server receive when the client sends those two lines?
Can you explain what the problem is?
Re: Java problems with encodings.
Quote:
Originally Posted by
lilezek
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).
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.
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:
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...
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.
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.
Re: Java problems with encodings.
Look at the constructors for the classes in the io package.
Re: Java problems with encodings.
I think you're right. Gonna try, and thank you for your patience.
Re: Java problems with encodings.
Good luck. Hard to test on one machine with one OS.
Re: Java problems with encodings.
Quote:
Originally Posted by
lilezek
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:
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.