Advertisement

09.20.2007 at 07:17AM PDT, ID: 22841407
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

implementing time-out in stop and wait protocol

Tags: wait, stop, protocol, c
Hi Experts
i need some modification in already made that works fine with no error:
I have the following code for sender.c
#include "assign1.h"
#include "sender.h"

extern int sTOr[2];
extern int rTOs[2];

FILE *fp;
static FRAME sendFrame;

void sender(char filename[]) {
        short blockNum = 0;
        char reply[5];

        sigignore(SIGINT);

        sendFrame.SOH = 00000001;
        sendFrame.blockNum=0;

        if ((fp = fopen(filename, "r")) == NULL) {
                perror("receiver(): fopen: ");
                exit(errno);
        }
        while ((readFile(sendFrame.msg)) > 0) {
                ++sendFrame.blockNum;
                sendFrame.blockNumComp = ~sendFrame.blockNum;
                sendFrame.checksum = makeChecksum(sendFrame.msg);

                printf("\nSENDER: blockNum = %d blockNumComp = %d checksum = %d\n", sendFrame.blockNum,
                        sendFrame.blockNumComp, sendFrame.checksum);
                write(sTOr[1], &sendFrame, sizeof(FRAME));

                while(1) {
                        read(rTOs[0], reply, sizeof("ACK"));
                        printf("%s was received\n", reply);

                        if (!strcmp(reply, "NAK")) {
                                printf("SENDER2: blockNum = %d blockNumComp = %d checksum = %d\n", sendFrame.blockNum,
                                        sendFrame.blockNumComp, sendFrame.checksum);
                                write(sTOr[1], &sendFrame, sizeof(FRAME));
                        }
                        else if (!strcmp(reply, "ACK"))
                                break;
                        else
                                exit(12);
                }
        }
}
int readFile(char *str) {
        int x;
        for(x = 0; x < 128; x++)
                str[x] = '\0';
        return fread(str, sizeof(char), 128, fp);
}
and the following code for receiver.c
#include "assign1.h"
#include "receiver.h"

FRAME rFrame;

void receiver() {

        sigset(SIGINT, makeError);

        while (1) {
                if (read(STDIN_FILENO, &rFrame, sizeof(FRAME)) > 0) {
                        sleep(1);

                        fprintf(stderr, "RECEIVER: blockNum = %d blockNumComp = %d checksum = %d\n", rFrame.blockNum,
                                rFrame.blockNumComp, rFrame.checksum);
                        if (!checkSOH(rFrame.SOH) ||
                            !checkBlockNum(rFrame.blockNum, rFrame.blockNumComp) ||
                            !checkChecksum(rFrame.msg, rFrame.checksum))
                                write(STDOUT_FILENO, "NAK", sizeof("NAK"));
                        else
                                write(STDOUT_FILENO, "ACK", sizeof("ACK"));
                }
        }
}

int checkSOH(char SOH){
        return (SOH == 00000001);
}

int checkBlockNum(const short blockNum, const short blockNumComp) {
        short newComp = ~blockNum;

        if (newComp == blockNumComp)
                return 1; // No error

        return 0; // Error
}

int checkChecksum(char *str, const short checksum) {
        if (makeChecksum(str) == checksum)
                return 1; // No error

        return 0; // Error
}

void makeError() {
        int n = rand()%3;
        switch (n) {
                case 0:
                        rFrame.blockNum = 0;
                        fputs("\nCHANGED BLOCK NUMBER\n", stderr);
                        break;
                case 1:
                        rFrame.checksum = 0;
                        fputs("\nCHANGED CHECKSUM\n", stderr);
                        break;
                case 2:
                        rFrame.blockNumComp = 10;
                        fputs("\nCHANGED BLOCK NUMBER COMPLIEMENT\n", stderr);
                        break;
        }
}

The program simulates different errors that the protocol checks for.I need to modify the program so that it implements "time out".
Theory:
Sender: sends a frame and calls a SIGALRM function and sets the timer for say, 2 seconds. If the sender gets a response within two seconds from the receiver (either "ACK" or "NAK"), turn off the alarm and transmit the next frame. If no response is received, time out function kicks in and retransmits the frame.

Receiver: When it sees an error in transmission, do not send back anything to the sender and this causes the to time out and retransmit.
Im new to C language please help me solve my problem

regards
shaukat
Start your free trial to view this solution
Question Stats
Zone: Networking
Question Asked By: shwaqar82
Solution Provided By: itsmeandnobodyelse
Participating Experts: 1
Solution Grade: B
Views: 39
Translate:
Loading Advertisement...
09.20.2007 at 08:38AM PDT, ID: 19929155

Rank: Guru

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
09.20.2007 at 09:16AM PDT, ID: 19929472

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
09.20.2007 at 10:37AM PDT, ID: 19930027

Rank: Guru

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
09.20.2007 at 10:43AM PDT, ID: 19930077

Rank: Guru

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
09.20.2007 at 10:52AM PDT, ID: 19930155

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
09.20.2007 at 08:11PM PDT, ID: 19933139

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
09.21.2007 at 01:10AM PDT, ID: 19933957

Rank: Guru

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
09.21.2007 at 01:13AM PDT, ID: 19933970

Rank: Guru

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
09.21.2007 at 05:49AM PDT, ID: 19935065

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
09.22.2007 at 01:35AM PDT, ID: 19940986

Rank: Guru

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
Loading Advertisement...
20080236-EE-VQP-29 / EE_QW_1_20070628