Solved

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

Posted on 1998-01-21
10
340 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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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
 

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
egit plugin on eclipse 8 82
use lov values 2 64
hashmap order 17 37
jsp error 6 27
For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

821 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