[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 183
  • Last Modified:

client server programming


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?

  • 2
2 Solutions
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);

any doubt
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 */

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


Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now