client server programming

Posted on 2005-05-08
Last Modified: 2010-04-15

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?

Question by:kotex11
    LVL 4

    Accepted Solution

    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);

    LVL 4

    Expert Comment

    any doubt
    LVL 45

    Assisted Solution

    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

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    Join & Write a Comment

    An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
    Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
    Video by: Grant
    The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
    The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now