Solved

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

Posted on 1998-01-21
10
334 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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

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…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…

759 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

22 Experts available now in Live!

Get 1:1 Help Now