PDA

View Full Version : Tell me what to do in following situation?



codeartist
28th May 2012, 13:14
I am thinking of creating a software that will have two systems:

1. Server code and Database
2. Client code and GUI codes.

When someone click the login button on my login page. I create a connection and connectToHost(). It gets connected. Then I need to know how can I get the data from database located on server system so that I can show the data on profile page.

Let suppose I need to retrieve name , address and photo.

Really need help regarding it!!!

Santosh Reddy
28th May 2012, 14:22
You need to design an application layer protocol which is understood both by server and client systems.

codeartist
28th May 2012, 20:14
Thanks for the reply. Can you show me a sample example.

Spitfire
30th May 2012, 15:13
pseudo-code:


// client
void requestUserData( int user_id )
{
socket->write( "GET_USER_DATA," + QString::number( user_id ) );
}

void newDataReceived( void )
{
QString data( socket->readAll() );
QStringList sl = data.split( "," );

if( sl.at( 0 ) == "USER_DATA" )
{
QString name = sl.at( 1 );
QString address = sl.at( 2 );
QString image = sl.at( 3 );
}
}

// server
void sendData( QString name, QString address, QString image )
{
socket->write( "USER_DATA," + name "," + address + "," + image );
}

void dataReceived( void )
{
QString data( socket->readAll() );
QStringList sl = data.split( "," );

if( sl.at( 0 ) == "GET_USER_DATA" )
{
int user_id = sl.at( 1 ).toInt();

sendData( users[user_id].name, users[user_id].address, users[user_id].image );
}
}

codeartist
1st June 2012, 04:56
Thanks! This is it! I needed this :)