Network Lab Pro Gams

Click here to load reader

  • date post

    19-Apr-2015
  • Category

    Documents

  • view

    38
  • download

    1

Embed Size (px)

Transcript of Network Lab Pro Gams

CHENGALPATTU 603 105

Name Register No. Course Year & Semester Lab Name

: :

: : :

B.E., CSE 3rd Year & 5th Semester

Network Lab

DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

Sl. No.

Date of Experiment

Name of the Experiment

Page No.

Signature of the Staff

1.

Programs using TCP Sockets (Client & Server) a) Implementation of Date and Time b) Implementation of ECHO c) Implementation of Chat

2

Programs using UDP Sockets (Client & Server) a) Implementation of Simple DNS b) Implementation of Date and Time

3 4 5 6 7 8 9

Program using RPC / RMI Simulation of Sliding window protocols Performance comparison of MAC Protocols RARP Implementation of Routing Protocols BGP Performance Comparison of Routing Protocols OSPF Study of UDP Performance Study of TCP Performance

Program // Implementation of Date and Time using TCP Sockets -client and server SERVER #include #include #include #include #include #include #include #include main() { int sd,i,len,bi,nsd,port; char content[30],buff[30],last_recieved[30]; struct sockaddr_in ser,cli; if((sd=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP))==-1) { printf("\nsocket problem"); return 0; } printf("\nsocket created\n"); bzero((char*)&cli,sizeof(ser)); printf("\nenter the port no:\n"); scanf("%d",&port); printf("\nport address is %d",port); ser.sin_family=AF_INET; ser.sin_port=htons(port); ser.sin_addr.s_addr=htonl(INADDR_ANY); bi=bind(sd,(struct sockaddr*)&ser,sizeof(ser)); if(bi==-1) { printf("\nbind error,prot busy,plz change port in client and server"); return 0; } i=sizeof(cli); listen(sd,5); nsd=accept(sd,((struct sockaddr*)&cli),&i); if(nsd==-1) { printf("\ncheck the description parameter\n"); return 0; } printf("\n connection accepted");

time_t ticks; ticks=time(NULL); snprintf(buff,sizeof(buff),"%24s\r\n",ctime(&ticks)); send(nsd,buff,30,0); printf("\nbye ...."); send(nsd,"eof",4,0); close(sd); close(nsd); return 0; } CLIENT #include #include #include #include #include #include #include int main() { int sd,con,port,i; char content[30]; struct sockaddr_in cli; if((sd=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP))==-1) { printf("\nsocket problem"); return 0; } bzero((char*)&cli,sizeof(cli)); cli.sin_family=AF_INET; printf("\nenter prot no:"); scanf("%d",&port); cli.sin_port=htons(port); cli.sin_addr.s_addr=htonl(INADDR_ANY); con=connect(sd,(struct sockaddr*)&cli,sizeof(cli)); if(con==-1) { printf("\nconnection error"); return 0; } i=recv(sd,content,30,0); printf("recieved from server %s\n",content); close(sd); return 0; }Date and Time using TCP Sockets

OUTPUT SERVER [[email protected] cse317]$ cc tserver.c [[email protected] cse317]$ ./a.out socket created enter the port no:1159 port address is 1159 connection accepted bye .... [[email protected] cse317]$

CLIENT [[email protected] cse317]$ cc tclient.c [[email protected] cse317]$ ./a.out enter prot no:1159 recieved from server Sat Oct 22 13:49:30 2011

[[email protected] cse317]$

Date and Time using TCP Sockets

Program // Implementation of Echo using TCP Sockets -client and server SERVER #include #include #include #include int main(int argc, char *argv[]) { socklen_t len; int listenfd,connfd,n; struct sockaddr_in servaddr,cliaddr; char buff[1024]; listenfd=socket(AF_INET,SOCK_STREAM,0); if(listenfd