J
Jim Bancroft
I'm writing out an integer to a socket using java. The client on the other
end is a plane-jane C program, and I'm having trouble figuring out why the
two of them won't talk properly.
I'm writing my integer using a DataOutputStream, like so:
String myString = Integer.toString(myInt);
DataOutputStrea, outp;
//....
outp.writeBytes(myString);
in the C client I'm doing this:
n = read(sockfd,mybuf,sizeof(mybuf));
....where mybuf is an unsigned char[16];
when it comes time to print the value I do this:
int newInt;
newInt = atoi(mybuf);
printf("the value is: %d\n", newInt);
But what happens is I get double values on the output. For instance, if the
java program has a value of "34" in myInt, the printf statement prints out
"3434". Same with every other integer I try.
I've looked at the mybuf array byte by byte and in fact, there are two
copies of my integer in there. Does anyone know what might be going on here
and what steps I can take to get C and Java to talk nice in this instance?
end is a plane-jane C program, and I'm having trouble figuring out why the
two of them won't talk properly.
I'm writing my integer using a DataOutputStream, like so:
String myString = Integer.toString(myInt);
DataOutputStrea, outp;
//....
outp.writeBytes(myString);
in the C client I'm doing this:
n = read(sockfd,mybuf,sizeof(mybuf));
....where mybuf is an unsigned char[16];
when it comes time to print the value I do this:
int newInt;
newInt = atoi(mybuf);
printf("the value is: %d\n", newInt);
But what happens is I get double values on the output. For instance, if the
java program has a value of "34" in myInt, the printf statement prints out
"3434". Same with every other integer I try.
I've looked at the mybuf array byte by byte and in fact, there are two
copies of my integer in there. Does anyone know what might be going on here
and what steps I can take to get C and Java to talk nice in this instance?