answersLogoWhite

0

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

13y ago

What else can I help you with?

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 can I effectively implement double sliding windows in my algorithm for optimizing window-based operations?

To effectively implement double sliding windows in your algorithm for optimizing window-based operations, you can use two pointers to track the start and end of the windows. Move the end pointer to expand the window while meeting the conditions, and move the start pointer to shrink the window when the conditions are not met. This approach can help efficiently process window-based operations in your algorithm.


Why does the window keep sliding down?

The window keeps sliding down because the mechanism that holds it in place is not working properly.


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.


What are the best window AC options available for side sliding windows?

The best window AC options for side sliding windows are portable air conditioners or specially designed sliding window air conditioners. These units are typically smaller and more flexible to fit in the narrow space of a side sliding window. Be sure to measure your window opening before purchasing to ensure a proper fit.


How can I install a sliding door window in my home?

To install a sliding door window in your home, you will need to measure the opening, purchase a sliding door window kit, remove the existing window, and follow the manufacturer's instructions for installation. It is recommended to seek professional help if you are not experienced in home improvement projects.