passing data around

Reply

Join Date: Mar 2007
Posts: 11
Reputation: fatboysudsy is an unknown quantity at this point 
Solved Threads: 0
fatboysudsy fatboysudsy is offline Offline
Newbie Poster

passing data around

 
0
  #1
Mar 25th, 2007
hi all,

I have been struggling for a while with my client/server program.
I have to authenticate in order to log on correctly.

I have managed to get most things sorted, asking for username ( which is a long integer (12) ) and also and customer ID (also an int (4)), and they are stored into 2 arrays. I can then send them from the client to the server.

For now all I am doing is printing the two integers out to see that they are correct, however when if I printf the data the numbers do not match what I typed into the client, and I do not know why ?

It is pointless trying to go onto the next stage of validating the numbers from a text file until i get this part sorted.

Somebody said that i needed to convert my integers into strings in my client program before sending them to the server as they will get corrupted...how on earth do i do this ? Is this true ? Do i need to do it, or is there another way?

Cheers for looking and any advice would be greatly appreciated.

Fatboy
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,343
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1458
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: passing data around

 
0
  #2
Mar 25th, 2007
If the client is MS-Windows and the server is *nix then you have Big Endian-Little Endian proglem The easiest way I know to correct it is to transfer the data as ascii text then use atol() or similar function on server side to convert back to integer in its own format.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Mar 2007
Posts: 11
Reputation: fatboysudsy is an unknown quantity at this point 
Solved Threads: 0
fatboysudsy fatboysudsy is offline Offline
Newbie Poster

Re: passing data around

 
0
  #3
Mar 25th, 2007
ok cool having looked at that description that does indeed sound like the problem, i am running this on unix by the way. however how do i change the integer into an ascii code ? thats the bit i cannot find or do !
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,343
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1458
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: passing data around

 
0
  #4
Mar 25th, 2007
>> i am running this on unix by the way
if both client and server are on the same os (unix) then the problem is something else.

>> how do i change the integer into an ascii cod
c++ example, use stringstream class
  1. #include <sstream>
  2. ...
  3. ...
  4. stringstream stream;
  5. int n = 123;
  6. stream << n;
  7. cout << stream.str();

c example
  1. #include <stdio.h>
  2. #include <string.h>
  3. ...
  4. ...
  5. char buffer[80];
  6. int n = 123;
  7. sprintf(buffer,"%d", n);
  8. printf("%s\n", buffer);
Last edited by Ancient Dragon; Mar 25th, 2007 at 4:26 pm.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC