answersLogoWhite

0


Best Answer

server side:

#include<sys/types.h>

#include<netinet/in.h>

#include<arpa/inet.h>

#define SIZE 4

main()

{

int std, lfd, len, i, j, status, sport;

char str[20], frame[20], temp[20], ack[20];

struct sockaddr_in saddr, caddr;

printf("Enter the port address");

scanf("%d", &sport);

std = socket(AF_INET, SOCK_STREAM, 0);

if(std<0)

perror("Error");

bzero(&saddr, sizeof(saddr));

saddr.sin_family = AF_INET;

saddr.sin_addr.s_addr = htonl(INADDR_ANY);

saddr.sin_port = htons(sport);

lfd = bind(std, (struct sockaddr *)&saddr, sizeof(saddr));

if(lfd)

perror("Bind Error");

listen(std, 5);

len = sizeof(&caddr);

lfd = accept(std, (struct sockaddr *)&caddr, &len);

printf("Enter the text:");

scanf("%s", str);i = 0;

while(i<strlen(str))

{

memset(frame, 0, 20);

strncpy(frame, str+i, SIZE);

printf("\nTransmitting frames:");

len = strlen(frame);

for(j=0; j<len; j++)

{

printf("%d", i+j);

sprintf(temp, "%d", i+j);

strcat(frame, temp);

}

write(lfd, frame, sizeof(frame));

read(lfd, ack, 20);

sscanf(ack, "%d", &status);

if(status 0)write(std, "-1", sizeof("-1"));

else{printf("Enter the sequence no of the frame where error has occured");

scanf("%s", err);

write(std, err, sizeof(err));

read(std, str, 20);

printf("Received the transmitted frame: %s\n", str);

}

}

close(std);

}

User Avatar

Wiki User

12y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

11y ago

WAP to implement Sliding Window protocol?

public class GoBackN

extends datalink.Protocol

{

int nextBufferToSend; // buffer to be sent when channel is idle

int firstFreeBufferIndex; // buffer in which to store next packet

int nextSequenceNumberExpected; // sequence number expected

int firstUnAcknowledged; // last unacknowledged frame

final int maximumSequenceNumber;

int numberOfPacketsStored;

final int windowSize;

datalink.Packet[] buffer;

double timer;

public GoBackN(int windowSize, double timer)

{

super( windowSize, timer);

numberOfPacketsStored = 0;

nextBufferToSend = 0;

firstFreeBufferIndex= 0;

nextSequenceNumberExpected = 0;

firstUnAcknowledged = 0;

maximumSequenceNumber = windowSize;

this.windowSize = windowSize;

this.timer = timer;

buffer = new datalink.Packet[windowSize+1];

}

public void FrameArrival( Object frame)

{

DataFrame f = (DataFrame) frame;

// a frame has arrived from the physical layer

// check that it is the one that is expected

if (f.sequenceNumber == nextSequenceNumberExpected)

{

sendPacket(f.info); // valid frame, so send it

// to the network layer

nextSequenceNumberExpected = inc( nextSequenceNumberExpected);

}

// if frame n is ACKed then that implies n-1, n-2 etc

// have also been

// ACKed, so stop associated timers.

while ( between( firstUnAcknowledged,

f.acknowledgment,

nextBufferToSend) )

{

numberOfPacketsStored--;

stopTimer(firstUnAcknowledged);

firstUnAcknowledged = inc( firstUnAcknowledged);

}

if ( numberOfPacketsStored < windowSize )

enableNetworkLayer();

}

public void PacketArrival( datalink.Packet p)

{

buffer[firstFreeBufferIndex] = p;

numberOfPacketsStored++; // buffer packet

if ( numberOfPacketsStored >= windowSize )

disableNetworkLayer();

if ( isChannelIdle() )

{

transmit_frame( nextBufferToSend);

nextBufferToSend = inc( nextBufferToSend);

}

firstFreeBufferIndex = inc( firstFreeBufferIndex);

}

public void TimeOut( int code)

{

int seq = inc(code);

while ( seq != nextBufferToSend )

{ // cancel outstanding timers

stopTimer(seq);

seq = inc( seq);

}

nextBufferToSend = firstUnAcknowledged;

if ( isChannelIdle() )

{

transmit_frame( nextBufferToSend);

nextBufferToSend = inc( nextBufferToSend);

}

}

public void CheckSumError()

{

}

public void ChannelIdle()

{

if ( nextBufferToSend != firstFreeBufferIndex )

{

transmit_frame( nextBufferToSend);

nextBufferToSend = inc( nextBufferToSend);

}

}

private boolean between( int a, int b, int c)

{ // calculate if a<=b<c circularly

if(((a<=b) && (b<c))

((c<a) && (a<=b))

((b<c) && (c<a)))

return true;

else

return false;

}

private int inc ( int a)

{ // increment modulo maximum_sequence_number + 1

a++;

a %= maximumSequenceNumber+1;

return a;

}

private void transmit_frame( int sequenceNumber)

{

int acknowledgement;

// piggyback acknowledge of last frame receieved

acknowledgement = (nextSequenceNumberExpected+maximumSequenceNumber)

% (maximumSequenceNumber+1);

// send it to physical layer

sendFrame( new DataFrame( sequenceNumber,

acknowledgement,

buffer[sequenceNumber]));

startTimer( sequenceNumber, timer);

}

}

class DataFrame

{ /* frame structure */

int sequenceNumber;

int acknowledgment;

datalink.Packet info;

DataFrame ( int s, int a, datalink.Packet p)

{

info = p;

sequenceNumber = s;

acknowledgment = a;

}

}

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you implement 1 bit sliding window protocol progamme in c?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering
Related questions

What are the advantages and disadvantages of onebit sliding window protocol?

Efficiency bandwith onebit sliding window protocol goback N selective repeat


Write a program to Silulate Sliding window protocol?

No, there is no possibility to do that.


Is there java source code for sliding window protocol?

YES


Simulation of sliding window protocol using java?

yes


Sliding window protocol using 3 bit sequence number and maximum window size of 4 Starting window positions at A and B before any frames are sent?

i need program C for sliding window protocl


Compare the sliding window protocol of data link layer and transport layer?

How to prepare for JEE Main 2015 Exam


How do I stop a window from sliding down on Intrigue?

replace the window regulator.


Can the center window be replaced with a rear sliding window on a Ford F-250?

I just shattered the rear sliding window of my Ford F250 and was told by Dave of Quality Glass in LaPorte IN that the current generation of rear sliding windows are designed so the glass cannot be removed to be replaced, so the answer given me was, I need to purchase a new sliding window assembly. I checked into replacing the sliding window with just straight glass and it actually cost me more than aftermarket sliding windows. This is not the definitive answer, but the working answer in my situation.


12 Discuss the advantages and disadvantages of credits versus sliding window protocols?

Sliding windows have only one set of parameters to use (window edges in the case of sliding windows), this makes them simpler. Also the problem when transport protocol data units are received in the wrong order causing windows to be increased and then decreased does not happen. On the other hand the credit scheme is more versatile and flexible and allows for the dynamic management of buffering separated from the acknowledgements


Can you install window film on sliding glass doors?

Yes, you can install window film on sliding glass doors because the sliding doors are still individual and not connected whereas it can disturb the film and come away.


What is the advantage of sliding window flow control over stop wait flow control?

As compared to stop-and-wait flow control the sliding window flow control has a far better performance. This is because in a wireless environment data rates are very low and noise level is very high, so waiting for an acknowledge for every packet that is transfered does not seem feasible. Thus,Transferring data as a bulk ( Once the medium is allocated ) would yield a better performance in terms of higher throughput. So the choice is sliding window flow control. Sliding window flow control is a point to point protocol assuming that no other entity tries to communicate until the current data transfer is complete by truqchalar


What is the advantage of sliding window flow control over stop-wait flow control?

As compared to stop-and-wait flow control the sliding window flow control has a far better performance. This is because in a wireless environment data rates are very low and noise level is very high, so waiting for an acknowledge for every packet that is transfered does not seem feasible. Thus,Transferring data as a bulk ( Once the medium is allocated ) would yield a better performance in terms of higher throughput. So the choice is sliding window flow control. Sliding window flow control is a point to point protocol assuming that no other entity tries to communicate until the current data transfer is complete by truqchalar