Solved

Sockets and swedish Characters (åäöÅÄÖ)

Posted on 1998-01-21
10
335 Views
Last Modified: 2013-12-03
I've got a problem with an applet that communicates with a server via a Socket connection. Here is the code for writing on the socket:
        Socket s = new Socket(serverMachine,                               Globals.SERVER_PORT);
        DataOutputStream outS =
                  new DataOutputStream(s.getOutputStream());
        outS.writeUTF("NEW_NOTE");
        outS.writeUTF(name);
        outS.writeUTF(text);
        outS.close();
        s.close();

Here is the code for reading on the socket (The server side): (on ServerSocket.accept() the following is don

        DataInputSteam in;

        String cmd  = in.readUTF();
        String name = in.readUTF();
      String info = in.readUTF();
        in.close();
        out.close();

This works fine except that the swedish characters becomes something else. I use the read and write-UTF because this was the only method that I thought I could use when writing a string that contained \n in it.

Is it the UTF-format that's cousing the problem? If it is, is there anyother method I can use that works in the same way?

Is there any alternative way's of doing this? I don't want to use RMI, CORBA or DCOM!
0
Comment
Question by:peed112097
  • 6
  • 4
10 Comments
 
LVL 5

Expert Comment

by:fontaine
ID: 1232421
Are you sure that it is a communication problem? It is maybe a Font problem. Did you already successfully write in Swedish in an applet, i.e.:

public void paint(Graphics g)
{
 g.drawString(...,30,30); // ... = Swedish word
}

gives on screen the right characters for the Swedish word?
0
 

Author Comment

by:peed112097
ID: 1232422
Thanks, the string is not ok in the applet! Any ideas on how to go arount this problem?
0
 
LVL 5

Expert Comment

by:fontaine
ID: 1232423
I suppose that you are writing directly in Swedish in your program. You should replace all non-ASCII characters by their Unicode representation and see what this gives.
0
 
LVL 5

Accepted Solution

by:
fontaine earned 210 total points
ID: 1232424
OK, I lock the question, as I have in fact answered to the UTF-format question, and greatly simplified the problem. But don't worry, we can continue discussing.

This could be a helpful resource:

Unicode site: http://www.unicode.org/
0
 
LVL 5

Expert Comment

by:fontaine
ID: 1232425
Taligent has developed a rich text widget. From the documentation, I can read:

"Although the RichText Widget uses Unicode characters, it is limited by the font capabilities in Java. Currently, the Java drawing environment is unable to display non-Roman glyphs. Once
this capability is provided, the RichText Widget will support text editing in non-Roman writing systems (such as Arabic and Japanese)."

http://ftp-products.taligent.com/RichText/documentation.html

So, if Swedish characters are non-Roman, you will currently be unable to do what you need. Otherwise, using Unicode should solve your problem.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:peed112097
ID: 1232426
Ok, I know that the question is awnsered and you'll get your points! But I'll be glad if you could help me out!

In the textarea and the textfield I'm using the characters åäö.. works fine, but when I print the string (System.out.println) the characters öåä... are not åäö...

I thought that Java always used unicode for representing characters?
0
 
LVL 5

Expert Comment

by:fontaine
ID: 1232427
I don't know if these characters are Roman or not. If not, as Java currently only supports Roman, it is normal that it doesn't work (even if they are furnished in Unicode). What you could do is turn your applet in an application and look what you have in the DOS window (if you are on a PC).

Also, if your browser doesn't support JDK 1.1, it is normal that it doesn't work because the I/O classes were threwing away the top eight bits of the character so that only ASCII was supported in Java prior to 1.1. You should test your applet with the appletviewer of a JDK > 1.1 to verify if this is the problem.
0
 

Author Comment

by:peed112097
ID: 1232428
I'm running the applet with JDK1.1 and I'm testing on a PC. Where can I find out whether the swedish language charachters are a part of Roman or not? I've looked at unicode.org, but I did'nt find anything about Roman!
0
 
LVL 5

Expert Comment

by:fontaine
ID: 1232429
No idea, I would have to search myself...
0
 

Author Comment

by:peed112097
ID: 1232430
Thanks for help,it seams as the swedish characters not are part of the roman char-set! Here's your points, and thanks for taking your time!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now