Sockets reading incorrect values

P

phantom

Hi all,

I have a server(java) listening to a client (non-Java), the client
is sending the hex values of the length of the string as unsigned
bytes to me. heres the situation:

Client send a hex value :
1st byte : 00
2nd byte : 31

Server reads the bytes correctly as
Byte Integer value ( using in.read())
0 0
31 31

this is all fine the problem starts when the client sends me a
char hex (a-f)
Client
1st byte 05
2nd byte bc

Server reads
Integer value
1st byte 5
2nd byte 65533

and it screws up the rest .
Not sure wat the workaround for this is

Thanking you in anticipation
Sid
 
?

=?ISO-8859-1?Q?Thomas_Gagn=E9?=

Why aren't you using middleware? Those problems (and other network
issues) are handled for you?
 
D

David Zimmerman

Trim off the the sign bits with a bitwise and

byte b = (byte)0xbc;
int i = 0xff & b;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top