You are on page 1of 5

Ex.No.

1 Date:

SOCKET CREATION USING TCP AND UDP

AIM: To write a c program to create a socket using TCP and UDP. ALGORITHM: Step 1: Start the program by including necessary header files. Step 2: Declare the variables. Step 3: Create a TCP socket and an socket using function socket (int, domain, int type, int protocol). Step 4: Verify whether the two socket are create or not by using if loop with their return value. Step 5: If return value is -1, socket is not created else socket is created. Step 6: End of the program.

PROGRAM: #include<stdio.h> #include<unistd.h> #include<sys/types.h> #include<sys/socket.h> int main() { int stad,suad; stad=socket(AF_INET,SOCK_STREAM,0); suad=socket(AF_INET,SOCK_DGRAM,0); if(stad==-1) { printf(socket not created); } else printf(TCP socket is created at %d\n,stad); if(suad==-1) { printf(socket not creatd); } else printf(UDP socket is created at %d\n,suad); }

Ex.No.2 Date:

SLIDING WINDOW PROTOCOL

AIM: To implement sliding window protocol in unix environment. ALGORITHM: Step 1: Start the program. Step 2: Open input output file in read mode. Step 3: Read the size of the window. Step 4: Select randomly the number of packets is to be transfered. Step 5: Read the content of the input output file. Step 6: Transfer the packet unitl it reaches the maximum defined size. Step 7: Resume the window size and repeat the above two steps unitl packets. Step 8: Close the file. Step 9: Stop the program.

PROGRAM: #include<stdio.h> #include<stdlib.h> main() { int i,j,m,n,w,k; char c; FILE *f; f=fopen(ex1.txt,r); printf(Window size); scanf(%d,&n); m=n; while(!feof(f)) { i=rand()%n+1; j=i; k=i; if(m>i) { m=m-i; if(m>0) { printf(\n); while(i>0 & !feof(f)) { C=getc(f); Printf(%c,c); i--; }

Printf(%d translated,j); if(j>3) printf(\n the acknowledgement received); else printf(\n the acknowledgemnt received, j+1); } } m=m+j-1; } }

You might also like