I'm sending an object of class account to client.when the server search for the
object in file it gets the object accurately but when it is sent to client and
seen its data it is found to be blank. please help
void login()
{
fflush(stdin);
struct log
{
char acc_number[50];
char password[50];
}u;
account acc;
int result=-3;
system("CLS");
cout<<"\n\nEnter account number : ";
gets(u.acc_number);
cout<<"\nEnter password : ";
gets(u.password);
send(commsocket,(char*)&u,500,0);
recv(commsocket,(char *)&result,4,0); //result check weather account logged in successfully(ie 1) or not(ie 0)
cout<<"Result from server : "<<result;
if(result==0)
{
cout<<"\nBad username or password";
getchar();
}
if(result==1)
{
recv(commsocket,(char*)&acc,500,0); //acc is the structure containing all the information about the account of user
cout<<"\nLogged in Successfully.Press any key to continue..... ";
cout<<"\nDetails are:";
acc.show_details();
getchar();
acc.showmenu();
}
}
The data that is received must match the data that's sent.
TCP has no mechanism for doing this, there are no records, fields, ..., you must ensure they match yourself.
You have to decide how much data to send, decide what your end of field, end of record markers are..., again, all that you have to do yourself. It's called a protocol.