cannot pass the object from server

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


//client function
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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();
    }
}





1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
//server function
void login()
{
    cout<<"\nReached login()";
    fflush(stdin);
    struct log
    {
        char acc_number[50];
        char password[50];
    };
    log u;
    account a;
    int result=0;
    cout<<"\nAbout to receive";
    recv(lsocket,(char*)&u,100,0);
    cout<<"\nRecieved...";
    cout<<"Acc_no: "<<u.acc_number;
    cout<<"Password: "<<u.password;
    
    ifstream f;
    f.open("BANK.PG");
    if(!f)
    {
        cout<<"File cannot be opened ";
        getchar();
    }
    while(1)
    {
        f.read((char*)&a,sizeof(a));
        if(strcmp(a.ret_acc_no(),u.acc_number)==0)
        {
            
            for(i=0;i<500;i++)
            {
                sendbuffer[i]=0;
            }
            result=1;
            strcpy(sendbuffer,(char*)&result);
            cout<<"Match found.Details are...";
            a.show_details();
            send(lsocket,sendbuffer,260,0);
            
            send(lsocket,(char*)&a,500,0);
            return;
        }
        if(f.eof())
            break;
    }
    result=0;
    for(i=0;i<500;i++)
    {
        sendbuffer[i]=0;
    }
    send(lsocket,(char*)&result,500,0);
    //Now control will return to main();
}
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.
what is meant by end of field and end of record markers ??
Topic archived. No new replies allowed.