J
Jim Bancroft
Hi everyone,
I have a Java class that opens a socket and connects with a client. The
client is written in C.
All goes well, but when it comes time to write a floating point value the
client has trouble reading it. I realize this isn't a C newsgroup but I was
hoping someone's seen what I'm experiencing and can help?
In a nutshell the java server looks like this:
SocketServer listener;
int portNumber;
Socket mySocket;
PrintWriter outp;
listener= new ServerSocket(portNumber);
mySocket=listener.accept();
outp = new PrintWriter(mySocket.getOutputStream(),true);
outp.println(85.6f);
The C client does this:
char[128] buffer;
int num;
float flt;
memset(buffer,'\0',sizeof(buffer));
n = read(sockfd,buffer,127);
flt=atof(buffer);
printf("You returned %lf from the server\n",flt);
The printf statement shows a value of 0.0000 no matter what floating point
value I send via the java server. If I send an integer from the server, I
have no problems using atoi() and printing it out.
Again, I know this is a java newsgroup but does anyone happen to know what
I'm doing wrong in my C code above?
I have a Java class that opens a socket and connects with a client. The
client is written in C.
All goes well, but when it comes time to write a floating point value the
client has trouble reading it. I realize this isn't a C newsgroup but I was
hoping someone's seen what I'm experiencing and can help?
In a nutshell the java server looks like this:
SocketServer listener;
int portNumber;
Socket mySocket;
PrintWriter outp;
listener= new ServerSocket(portNumber);
mySocket=listener.accept();
outp = new PrintWriter(mySocket.getOutputStream(),true);
outp.println(85.6f);
The C client does this:
char[128] buffer;
int num;
float flt;
memset(buffer,'\0',sizeof(buffer));
n = read(sockfd,buffer,127);
flt=atof(buffer);
printf("You returned %lf from the server\n",flt);
The printf statement shows a value of 0.0000 no matter what floating point
value I send via the java server. If I send an integer from the server, I
have no problems using atoi() and printing it out.
Again, I know this is a java newsgroup but does anyone happen to know what
I'm doing wrong in my C code above?