0% found this document useful (0 votes)
4 views3 pages

Leaky

Uploaded by

sytlog43
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views3 pages

Leaky

Uploaded by

sytlog43
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

#include<stdio.

h>
int main()
{
int n,bsize,ln,out,store=0;
printf("enter the bucketsize outgoing rate and number of inputs");
scanf("%d%d%d",&bsize,&out,&n);
while(n!=0)
{
printf("enter the incoming packet size");
scanf("%d",&ln);
if(ln<=(bsize-store))
{
store+=ln;
printf("before outgoing,bucket size %d occupied out of %d\n",store,bsize);
}
else
{
printf("incoming packets %d discarded out of ?%d\n ",ln-(bsize-store),ln);
store=bsize;
printf("before outgoing,bucket size %d occupied out of %d\n",store,bsize);
}
if(store>out)
store-=out;
else
store-=0;
printf("after outgoing bucket size %d occupied out of %d\n",store,bsize);
n--;
}
}

output
enter the bucketsize outgoing rate and number of inputs 10
2
3
enter the incoming packet size 4
before outgoing,bucket size 4 occupied out of 10
after outgoing bucket size 2 occupied out of 10
enter the incoming packet size5
before outgoing,bucket size 7 occupied out of 10
after outgoing bucket size 5 occupied out of 10
enter the incoming packet size5
before outgoing,bucket size 10 occupied out of 10
after outgoing bucket size 8 occupied out of 10
CLIENT
#include<stdio.h>
#include<sys/types.h>
#include<sys/socket.h>
#include<netinet/in.h>
#include<netdb.h>
#include<stdlib.h>
#include<string.h>
#include<unistd.h>
#define SERV_TCP_PORT 5035
#define MAX 60
int main(int arg, char*argv[])
{
int sockfd,n;
struct sockaddr_in serv_addr;
struct hostent*server;
char send [MAX], recvline [MAX], s [MAX], name [MAX];
sockfd=socket (AF_INET, SOCK_STREAM, 0);
serv_addr.sin_family=AF_INET;
serv_addr.sin_addr.s_addr=inet_addr ("127.0.0.1");
serv_addr.sin_port=htons (SERV_TCP_PORT);
connect(sockfd, (struct sockaddr*)&serv_addr, sizeof(serv_addr));
printf("\nEnter the source file name: \n");
scanf("%s", send);
write(sockfd, send, MAX);
while((n=read (sockfd, recvline, MAX))!=0)
{
printf("%s", recvline);
}
close(sockfd);
return 0;
}

output
Enter the source file name:
ftpfile.c
ftp output

SERVER
#include<stdio.h>
#include<arpa/inet.h>
#include<sys/types.h>
#include<sys/socket.h>
#include<netinet/in.h>
#include<netdb.h>
#include<stdlib.h>
#include<string.h>
#include<unistd.h>
#define SERV_TCP_PORT 5035
#define MAX 60
int i, j, tem;
char buff[4096], t;
FILE *f1;
int main(int afg, char *argv)
{
int sockfd, newsockfd, clength;
struct sockaddr_in serv_addr, cli_addr;
char t[MAX], str[MAX];
strcpy(t, "exit");
sockfd=socket (AF_INET, SOCK_STREAM, 0);
serv_addr.sin_family=AF_INET;
serv_addr.sin_addr.s_addr=INADDR_ANY;
serv_addr.sin_port=htons (SERV_TCP_PORT);
printf("\nBinded");
bind (sockfd, (struct sockaddr*)&serv_addr,sizeof(serv_addr));
printf("\nListening..."); listen (sockfd, 5);
clength=sizeof(cli_addr);
newsockfd=accept (sockfd, (struct sockaddr*)&cli_addr,&clength);
close(sockfd);
read(newsockfd, &str, MAX);
printf("\nClient message\n File Name : %s\n",str);
f1=fopen(str, "r");
while(fgets(buff, 4096, f1) !=NULL)
{
write(newsockfd, buff, MAX);
printf("\n");
}
fclose(f1);
printf("\nFile Transferred\n");
return 0;
}

output
Binded
Listening...
Client message
File Name : ftpfile.c

You might also like