help: send unicode text using sockets

Hi,

I am trying to send unicode text to a native app using sockets. My test code looks like this

Socket socket = new Socket(m_serverHost, m_hostPort);

OutputStreamWriter out = new OutputStreamWriter(socket.getOutputStream(), "UTF-8");

InputStreamReader reader = new InputStreamReader(socket.getInputStream(), "UTF-8");

BufferedReader in = new BufferedReader(reader);

// receive response to connect

byte[] rc = new byte[4];

int i = 0;

while (i < 4)

{

rc[i++] = (byte) in.read();

}

String text = new String("Hello");

out.write(text);

// receive response to "hello"

i = 0;

while (i < 4)

{

rc[i++] = (byte) in.read();

}

My test program is connecting to the server socket but the server does not seem to understand the text that I send.

Please comment if I am doing anything wrong or advice if you have any different ideas.

Thanks,

nallamos

[1006 byte] By [nallamos] at [2007-9-26 4:40:38]
# 1
hi,As far as your code is concerned it seems pretty much OK. I cannot understand why it is not working but apparently the problem may lie elsewhere.However donot forget to close the output stream after out.write(text);out.close(); Khurram
kilyas at 2007-6-29 18:02:19 > top of Java-index,Desktop,I18N...
# 2

Try using the following output and input streams.

out = new DataOutputStream(

new BufferedOutputStream(

s.getOutputStream()));

in = new DataInputStream(

new BufferedInputStream(

s.getInputStream()));

When you send the data send it using

out.WriteBytes(message)

jeffdimarco at 2007-6-29 18:02:19 > top of Java-index,Desktop,I18N...
# 3
do a out.flush()after you write to the outputStream
bharatchhajer at 2007-6-29 18:02:19 > top of Java-index,Desktop,I18N...
# 4
Wrap your input and output streams withDataInputStream and DataOutputStreamsince they have methods likereadUTF()writeUTF()which made to send and recive unicode text.
bharatchhajer at 2007-6-29 18:02:19 > top of Java-index,Desktop,I18N...