?
Solved

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

Posted on 1998-01-21
10
Medium Priority
?
344 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 5

Accepted Solution

by:
fontaine earned 630 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

Question has a verified solution.

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

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses
Course of the Month11 days, 22 hours left to enroll

752 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