• C

client server programming

Hi,

I am doing a project in GSM. I have the bits in a file. I need to pack say 100 bits in 1 frame send it to the server.

Please guide me on how to go about this and at what level shud i code i.e. should i code at the protocol stack level?

sandosh
kotex11Asked:
Who is Participating?
 
smpoojaryConnect With a Mentor Commented:
I think, you can use socket programming for send frame to server.
client side
1. while(!feof(fp))
2. read 100 bits from input file
   2.1 unsigned long frame[4] ;
   2.2 store 100 bits to frame using bitwise <<,>>,& (AND),|(OR), operators and append other bits of frame to 0's
   2.3 send it to server using send(sock,frame,sizeof(frame),0);
3.

-Mahesh
0
 
smpoojaryCommented:
any doubt
0
 
sunnycoderConnect With a Mentor Commented:
Hi Sandosh,

You need to elaborate your question a bit more. When you say 100 bits from a file, how are the bits stored? Is it a string like "110111011110000101001..." or are they stored as characters representing those bit sequences or a string of hex values or something else?

Depending on the storage format, your input routine would be formulated.

In C, individual bits cannot be addressed directly. They can be set and read using bitwise operators.
Once you have read the input, next task would be to fit the bits in memory in a format which your communicating counterpart understands.
e.g. You file had string "01101101" ... Note that this is a string of characters taking up a total of 9 bytes (assuming 1 byte per char). To convert it into bits packed into a char, you need to loop through the string setting bits in char correspondingly, something like

while ( string[i] != '\0' )
{
       if (string[i] == '1')            /* If i-th char is 1, we want the corresponding i-th bit to be set to 1, we check if we want that here */
              mychar = mychar | (1<<i);        /* this does the set by shifting 1 by i places and ORing it with mychar */
       i++;
}

If you are looking for some other packing format, you need to elborate on it.

Cheers!
sunnycoder
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.