sending Chararray of hexadecimal

Hi everyone.

im trying to send a chararray of hexadecimal in a socket, but when i catch it on the server it's not the same chararray...

this is the array i am sending from the client:

char[] _envio ={0x00,0x4C,0x60,0x00,0x05,0x80,0xE3,0x08,0x00,0x20,0x20,0x61,0x01,0x80,0xC0,0x00,0x02,

0x95,0x00,0x00,0x01,0x05,0x82,0x12,0x34,0x01,0x23,0x00,0x01};

and this is what i am getting on the server:

0 4C 60 05 3F E3 8 0 20 20 61 1 3F C0 02 3F 0 0 15 3F12 34 1 23 01

note that the problem is when the hexadecimal is 0x80, 0x95 and 0x82 it is always change by 3F...

can someone tell me why this is happening?

this is how i am sending the chararray

char[] _envio ={0x00,0x4C,0x60,0x00,0x05,0x80,0xE3,0x08,0x00,0x20,0x20,0x61,0x01,0x80,0xC0,0x00,0x02,

0x95,0x00,0x00,0x01,0x05,0x82,0x12,0x34,0x01,0x23,0x00,0x01};

try

{

_serversocket =new Socket(_ipserver, _portserver);

_out =new PrintStream(_serversocket.getOutputStream());

_in =new BufferedReader(new InputStreamReader(

_serversocket.getInputStream()));

_out.println(_envio);

}

catch (UnknownHostException ex)

{

ex.printStackTrace();

}

and this is how i am chatching it in the server

try

{

_in =new BufferedReader(new InputStreamReader(

_clientsocket.getInputStream()));

_out =new PrintStream(_clientsocket.getOutputStream());

_in.read(_msj);

System.out.print("Mensaje del cliente: ");

for(int i = 0; i < _msj.length; i++)

{

System.out.print(Integer.toHexString((int)_msj[i]).toUpperCase());

}

System.out.println();

}

catch (IOException ex)

{

ex.printStackTrace();

}

[2698 byte] By [Bianconero_ccsa] at [2007-9-25]
# 1

Instead of PrintStream and BufferedReader (with InputStreamReader) you should use [url http://java.sun.com/j2se/1.5.0/docs/api/java/io/DataOutputStream.html#writeChar(int)]DataOutputStream.writeChar()[/url] and [url http://java.sun.com/j2se/1.5.0/docs/api/java/io/DataInputStream.html#readChar()]DataInputStream.readChar()[/url] because there is no special conversion involved.// client:

_out = new DataOutputStream(_serversocket.getOutputStream());

for (int i = 0; i < _envio.length; i++)

_out.writeChar(_envio[i]);

// server:

_in = new DataInputStream(_clientsocket.getInputStream());

for (int i = 0; i < _msj.length; i++)

_msj[i] = _in.readChar();

Regards

jfbrierea at 2007-7-14 > top of java,Archived Forums,Socket Programming...
# 2
ok thanx let me test it
Bianconero_ccsa at 2007-7-14 > top of java,Archived Forums,Socket Programming...
# 3
thanx man, it really works, the only problem now i have, is when i dont know the lengh of the messagge incoming the server remains in a endless loop, so for now i use a special character to stop the loop.any suggestion will be helpfullthank you again.
Bianconero_ccsa at 2007-7-14 > top of java,Archived Forums,Socket Programming...
# 4
Send the length before the data so the reader knows how much to read before it has to read it.
ejpa at 2007-7-14 > top of java,Archived Forums,Socket Programming...