[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[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!

6.2

implementing time-out in stop and wait protocol

Asked by shwaqar82 in Networking Protocols, C Programming Language, Network Analysis Software

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
[+][-]09/20/07 08:38 AM, ID: 19929155Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09/20/07 09:16 AM, ID: 19929472Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09/20/07 10:37 AM, ID: 19930027Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zones: Networking Protocols, C Programming Language, Network Analysis Software
Tags: wait, stop, protocol, c
Sign Up Now!
Solution Provided By: itsmeandnobodyelse
Participating Experts: 1
Solution Grade: B
 
[+][-]09/20/07 10:43 AM, ID: 19930077Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09/20/07 10:52 AM, ID: 19930155Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09/20/07 08:11 PM, ID: 19933139Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09/21/07 01:10 AM, ID: 19933957Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09/21/07 01:13 AM, ID: 19933970Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09/21/07 05:49 AM, ID: 19935065Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09/22/07 01:35 AM, ID: 19940986Assisted Solution

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 30-day free trial to view this Assisted Solution or ask the Experts your question.

 
 
Loading Advertisement...
20091111-EE-VQP-89 / EE_QW_1_20070628