Solved

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

Posted on 1998-01-21
10
338 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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
groupSum6 challenge 6 86
VB Script to add site to Java Exception List 4 76
Apps blocked by Java 9 79
egit plugin on eclipse 8 62
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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 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…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

776 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