Sie sind auf Seite 1von 22

EXNO: 1.

A TCP SOCKET
AIM:
To implement File Transfer Program Using TCP Sockets
// SERVER PROGRAM
#include<sys/types.h>
#include<fcntl.h>
#include<sys/socket.h>
#include<stdio.h>
#include<netinet/in.h>
#include<unistd.h>
#include<stdli.h>
#include<string.h>
main!"
#
int sockfd$confd$pid$fd$in$addr$list$n%
char uff&'()*++$uff,&,(-.)*++%
sockfd*socket!/F0123T$S4C50ST63/7$("%
struct sockaddr0in ser8er%
9ero!:ser8er$si9eof!ser8er""%
ser8er.sin0family*/F0123T%
ser8er.sin0port*htons!,,,-"%
addr*inet0aton!+,-;.(.(.,+$:ser8er.sin0addr.s0addr"%
printf!+/ddr<=d>n+$addr"%
in*ind!sockfd$!struct sockaddr?":ser8er$si9eof!ser8er""%
printf!+@ind<=d>n+$in"%
list*listen!sockfd$'"%
printf!+Aisten<=d>n+$list"%
for!%%"
#
confd*accept!sockfd$($("%
printf!+=d+$confd"%
pid*fork!"%
if!pid**("
#
close!sockfd"%
read!confd$uff$'("%
printf!+File2ame<=s>n+$uff"%
fd*open!uff$406B42AC"%
if!fd<("
Drite!confd$+File not eEist+$strlen!+File not eEist+""%
if!fd>("
Dhile!read!fd$uff,$,(-.""
#
n*Drite!confd$uff,$strlen!uff,""%
F
close!confd"%
eEit!("%
F
F
close!confd"%
F
//CLIENT PROGRAM
#include<sys/types.h>
#include<fcntl.h>
#include<sys/socket.h>
#include<stdio.h>
#include<netinet/in.h>
#include<unistd.h>
#include<string.h>
#include<stdli.h>
main!"
#
int sockfd$confd$con$addr$n%
char fname&'()*++$uff&,(-.)*++%
struct sockaddr0in client%
sockfd*socket!/F0123T$S4C50ST63/7$("%
9ero!:client$si9eof!client""%
client.sin0family*/F0123T%
client.sin0port*htons!,,,-"%
addr*inet0aton!+,-;.(.(.,+$:client.sin0addr.s0addr"%
printf!+/ddr<=d>n+$addr"%
con*connect!sockfd$!struct sockaddr?":client$si9eof!client""%
printf!+Connection<=d>n+$con"%
printf!+3nter the file name<>n+"%
scanf!+=s+$fname"%
Drite!sockfd$fname$strlen!fname""%
n*read!sockfd$uff$,(-."%
printf!+=s>n+$uff"%
close!sockfd"%
F
// OUTPUT:
//S36G36 PH7 4UTPUT
&rootIlocalhost J)# gcc filesertcp.c Ko fileser
&rootIlocalhost J)# ./fileser
S36G36 PH7
@ind <(
File 2ame <thiagu.c
Filecontent
main!"
#
printf!+thiagu+"%
F
//CA132T PH7 4UTPUT<
&rootIlocalhost J)# gcc fileclitcp.c Ko filecli
&rootIlocalhost J)# ./filecli
CA132T PH7
3nter the File name<thiagu.c
File Contents
main!"
#
printf!+thiagu+"%
F
RESULT:
Thus the ao8e program a clientKser8er application for chat using TCP Das eEecuted and
successfully
EXNO: 1.B UDP SOCKET
AIM:
To implement File Transfer Program Using UBP Socket
//SERVER PROGRAM
#include<stdio.h>
#include<sys/types.h>
#include<sys/socket.h>
#include<netd.h>
#include<fcntl.h>
#include<stdli.h>
#include<netinet/in.h>
#include<string.h>
main!"
#
int sfd$$len$fd%
char fn&,(()*++$fn,&,(-.)*+File not eEists+$fc&,(-.)*++%
printf!+>nS36G36 PH7>n+"%
struct sockaddr0in saddr$caddr%
sfd*socket!/F0123T$S4C50BH6/7$("%
9ero!:saddr$si9eof!saddr""%
saddr.sin0family*/F0123T%
saddr.sin0port*htons!,,L,"%
saddr.sin0addr.s0addr*htonl!12/BB60/2C"%
*ind!sfd$!struct sockaddr?":saddr$si9eof!saddr""%
printf!+>n@ind <=d>n+$"%
for!%%"
#
len*si9eof!caddr"%
rec8from!sfd$fn$si9eof!fn"$($!struct sockaddr?":caddr$:len"%
printf!+>nFile 2ame <=s>n+$fn"%
fd*open!fn$406B42AC"%
if!fd<("
sendto!sfd$fn,$si9eof!fn,"$($!struct sockaddr?":caddr$si9eof!caddr""%
else
#
Dhile!read!fd$fc$si9eof!fc"""
#
sendto!sfd$fc$si9eof!fc"$($!struct sockaddr?":caddr$si9eof!caddr""%
printf!+Filecontent>n=s>n+$fc"%
F
F
F
close!sfd"%
F
// CLIENT PROGRAM
#include<stdio.h>
#include<sys/types.h>
#include<fcntl.h>
#include<sys/socket.h>
#include<netd.h>
#include<netinet/in.h>
#include<string.h>
#include<stdli.h>
#include<arpa/inet.h>
main!"
#
int sfd$len%
char fn&,(-.)*++$fn,&,(-.)*++%
struct sockaddr0in saddr%
printf!+>nCA132T PH7>n+"%
sfd*socket!/F0123T$S4C50BH6/7$("%
9ero!:saddr$si9eof!saddr""%
saddr.sin0family*/F0123T%
saddr.sin0port*htons!,,L,"%
saddr.sin0addr.s0addr*htonl!12/BB60/2C"%
for!%%"
#
printf!+>n3nter the File name<+"%
scanf!+=s+$fn"%
len*si9eof!saddr"%
sendto!sfd$fn$si9eof!fn"$($!struct sockaddr?":saddr$si9eof!saddr""%
Dhile!rec8from!sfd$fn,$si9eof!fn,"$($!struct sockaddr?":saddr$:len""
#
printf!+>nFile Contents>n=s>n+$fn,"%
F
F
close!sfd"%
F
// OUTPUT:
//S36G36 PH7 4UTPUT
&rootIlocalhost J)# gcc fileserudp.c Ko fileser
&rootIlocalhost J)# ./fileser
S36G36 PH7
@ind <(
File 2ame <thiagu.c
Filecontent
main!"
#
printf!+thiagu+"%
F
//CA132T PH7 4UTPUT<
&rootIlocalhost J)# gcc filecliudp.c Ko filecli
&rootIlocalhost J)# ./filecli
CA132T PH7
3nter the File name<thiagu.c
File Contents
main!"
#
printf!+thiagu+"%
F
RESULT:
Thus the ao8e program a clientKser8er application for chat using UBP Das eEecuted
and successfully
EXNO: 1.C APPLICATIONS USING SOCKETS
AIM:
To implement 3cho Client Ser8er Program Using UBP Sockets
// CLIENT PROGRAM
#include<stdio.h>
#include<sys/types.h>
#include<fcntl.h>
#include<sys/socket.h>
#include<netd.h>
#include<netinet/in.h>
#include<string.h>
#include<arpa/inet.h>
main!"
#
int sfd$len%
char msg&,()$msg,&,()*++%
struct sockaddr0in saddr$caddr%
printf!+>nCA132T PH7>n+"%
sfd*socket!/F0123T$S4C50BH6/7$("%
9ero!:saddr$si9eof!saddr""%
saddr.sin0family*/F0123T%
saddr.sin0port*htons!,,L,"%
saddr.sin0addr.s0addr*htonl!12/BB60/2C"%
for!%%"
#
printf!+>n3nter the String<+"%
scanf!+=s+$msg"%
len*si9eof!saddr"%
sendto!sfd$msg$,($($!struct sockaddr?":saddr$len"%
rec8from!sfd$msg$si9eof!msg"$($!struct sockaddr?":saddr$:len"%
printf!+>n7sg from Ser8er <=s>n+$msg"%
F
eEit!("%
close!sfd"%
F
//SERVER PROGRAM
#include<stdio.h>
#include<sys/types.h>
#include<sys/socket.h>
#include<netd.h>
#include<fcntl.h>
#include<netinet/in.h>
#include<string.h>
main!"
#
int len$sfd$$n%
char msg&,()*++$msg,&,()*++%
printf!+>nS36G36 PH7>n+"%
struct sockaddr0in saddr$caddr%
sfd*socket!/F0123T$S4C50BH6/7$("%
9ero!:saddr$si9eof!saddr""%
saddr.sin0family*/F0123T%
saddr.sin0port*htons!,,L,"%
saddr.sin0addr.s0addr*htonl!12/BB60/2C"%
*ind!sfd$!struct sockaddr?":saddr$si9eof!saddr""%
printf!+>n@ind <=d>n+$"%
for!%%"
#
len*si9eof!caddr"%
n*rec8from!sfd$msg$,($($!struct sockaddr?":caddr$:len"%
if!n**("
printf!+>n 2othing to display>n+"%
printf!+>n7sg from client <=s>n+$msg"%
sendto!sfd$msg$si9eof!msg"$($!struct sockaddr?":caddr$si9eof!caddr""%
F
close!sfd"%
F
OUTPUT:
Client<
Mai Ser8er
Ser8er<Mai Ser8er
Client<
Mello
Ser8er<Mello
Client<
end
Ser8er<end
RESULT:
Thus the ao8e program a 3cho clientKser8er application for chat using UBP Das
eEecuted and successfully
EXNO: 2 SIMULATIONS OF SLIDING WINDOW PROTOCOL
AIM:
To Drite a C program to perform sliding DindoD.
CLIENT:
#include <stdio.h>
#include <stdli.h>
#include <string.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/msg.h>
struct mymsguf
#
long mtype%
char mteEt&-')%
F%
F1A3 ?fp%
int main!"
#
struct mymsguf uf%
int msgid%
int i*($s%
int count*($frms9%
int a&,(()%
char d%
if!!msgid*msgget!NO$1PC0C63/TP(LLL""**K,"
#
printf!+>n 36646 12 7SHH3T+"%
eEit!("%
F
printf!+>n 3nter the frame si9e<+"%
scanf!+=d+$:frms9"%
if!!fp*fopen!+check+$+r+""**2UAA"
printf!+>n F1A3 24T 4P323B+"%
else
printf!+>n F1A3 4P323B+"%
Dhile!Qfeof!fp""
#
d*getc!fp"%
a&i)*d%
iRR%
F
s*i%
for!i*(%i<frms9%iRR" //print from the check file
printf!+>t =c+$a&i)"%
for!i*(%i<frms9%iRR"
#
if!!msgrc8!msgid$:uf$si9eof!uf"$($,""**K,"
#
printf!+>n 36646 12 7SH6CG+"%
eEit!("%
F
printf!+>n 63C31G3B F6/73S /63<=c+$uf.mteEt&i)"%
F
for!i*(%i<frms9%iRR"
#
if!a&i)**uf.mteEt&i)"
countRR%
F
if!count**("
#
printf!+>n F6/73S S363 24T 63C31G3B 12 C4663CT S3T+"%
eEit!("%
F
if!count**frms9"
#
printf!+>n F6/73S S363 63C31G3B 12 C4663CT S3T+"%
F
else
#
printf!+>n F6/73S S363 24T 63C31G3B 12 C4663CT S3T+"%
F
F
Slidin Wind!" P#!$!%!l & S'#('#
#include <stdio.h>
#include <stdli.h>
#include <string.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/msg.h>
struct mymsguf
#
long mtype%
char mteEt&-')%
F%
F1A3 ?fp%
int main!"
#
struct mymsguf uf%
int si$ei$s9%
int msgid%
int i*($s%
int a&,(()%
char d%
if!!fp*fopen!+send+$+r+""**2UAA"
printf!+>n F1A3 24T 4P323B+"%
else
printf!+>n F1A3 4P323B+"%
printf!+>n 3nter starting and ending indeE of frame array<+"%
scanf!+=d=d+$:si$:ei"%
s9*eiKsi%
if!!msgid*msgget!NO$1PC0C63/TP(LLL""**K,"
#
printf!+>n 36646 12 7SHH3T+"%
eEit!("%
F
Dhile!Qfeof!fp""
#
d*getc!fp"%
a&i)*d%
iRR%
F
s*i%
uf.mtype*,%
for!i*si%i<*ei%iRR"
#
uf.mteEt&i)*a&i)%
F
for!i*si%i<*ei%iRR" //the frames to e sent
printf!+>t =c+$uf.mteEt&i)"%
for!i*(%i<*s9%iRR"
#
if!!msgsnd!msgid$:uf$si9eof!uf"$(""**K,"
#
printf!+>n 36646 12 7SHS2B+"%
eEit!("%
F
F
printf!+>n F6/73S S32T+"%
return (%
F
O)$*)$:
&uni8,( I DDD uni8,()U cat >send
netDorkingla
&,V)R Stopped cat >send
&uni8,( I DDD uni8,()U cat send
netDorkingla
SERVER:
&uni8,( I DDD uni8,()U cc sDpser8er.c
&uni8,( I DDD uni8,()U ./a.out
F1A3 4P323B
3nter starting and ending indeE of frame array<( L
n e t D o r k
F6/73S S32T&uni8,( I DDD uni8,()U
CLIENT:
&uni8,( I DDD uni8,()U cc sDpclient.c
&uni8,( I DDD uni8,()U ./a.out
3nter the frame si9e<;
F1A3 4P323B n e t D o r k
63C31G3B F6/73S /63<n
63C31G3B F6/73S /63<e
63C31G3B F6/73S /63<t
63C31G3B F6/73S /63<D
63C31G3B F6/73S /63<o
63C31G3B F6/73S /63<r
63C31G3B F6/73S /63<k
F6/73S S363 63C31G3B 12 C4663CT S3T
RESULT:
Thus the ao8e program sliding DindoD protocol Das eEecuted and successfully.
EX NO: + SIMULATIONS OF ROUTING PROTOCOL
AIM:
To simulate the 1mplementing 6outing Protocols
P#!#,- :
#include <stdio.h>
#include<conio.h>
int main!"
#
int n%
int i$W$k%
int a&,()&,()$&,()&,()%
printf!+>n 3nter the numer of nodes<+"%
scanf!+=d+$:n"%
for!i*(%i<n%iRR"
#
for!W*(%W<n%WRR"
#
printf!+>n 3nter the distance etDeen the host =d K =d<+$iR,$WR,"%
scanf!+=d+$:a&i)&W)"%
F
F
for!i*(%i<n%iRR"
#
for!W*(%W<n%WRR"
#
printf!+=d>t+$a&i)&W)"%
F
printf!+>n+"%
F
for!k*(%k<n%kRR"
#
for!i*(%i<n%iRR"
#
for!W*(%W<n%WRR"
#
if!a&i)&W)>a&i)&k)Ra&k)&W)"
#
a&i)&W)*a&i)&k)Ra&k)&W)%
F
F
F
F
for!i*(%i<n%iRR"
#
for!W*(%W<n%WRR"
#
&i)&W)*a&i)&W)%
if!i**W"
#
&i)&W)*(%
F
F
F
printf!+>n The output matriE<>n+"%
for!i*(%i<n%iRR"
#
for!W*(%W<n%WRR"
#
printf!+=d>t+$&i)&W)"%
F
printf!+>n+"%
F
getch!"%
F
O)$*)$:
&uni8,( I DDD uni8,()U cc gp.c
&uni8,( I DDD uni8,()U ./a.out
3nter the numer of nodes<.
3nter the distance etDeen the host , K ,<'
3nter the distance etDeen the host , K -<O
3nter the distance etDeen the host , K V<L
3nter the distance etDeen the host , K .<.
3nter the distance etDeen the host - K ,<-
3nter the distance etDeen the host - K -<,
3nter the distance etDeen the host - K V<N
3nter the distance etDeen the host - K .<V
3nter the distance etDeen the host V K ,<L
3nter the distance etDeen the host V K -<,
3nter the distance etDeen the host V K V<.
3nter the distance etDeen the host V K .<-
3nter the distance etDeen the host . K ,<'
3nter the distance etDeen the host . K -<,
3nter the distance etDeen the host . K V<N
3nter the distance etDeen the host . K .<-
' O L .
- , N V
L , . -
' , N -
The output matriE<
( ' L .
- ( N V
V , ( -
V , N (

RESULT:

Thus the ao8e program to simulate the 1mplementing 6outing Protocols using order gateDay
protocol Das eEecuted and successfully.
EX NO: . PROGRAMS USING RPC
AIM:
To implement the program using 6PC
ADD CLIENT:
import Wa8a.rmi.?%
pulic class /ddClient
#
pulic static 8oid main!String args&)"
#
try
#
String addSer8erU6A*+rmi<//+Rargs&()R+//ddSer8er+%
/ddSer8er1ntf addSer8er1ntf*!/ddSer8er1ntf"2aming.lookup!addSer8erU6A"%
System.out.println!+the first numer is+Rargs&,)"%
doule d,*Boule.8alue4f!args&,)".douleGalue! "%
System.out.println!+the Second numer is+Rargs&-)"%
doule d-*Boule.8alue4f!args&-)".douleGalue!"%
System.out.println!+the sum is +RaddSer8er1ntf.add!d,$d-""%
F
catch!3Eception e"
#
System.out.println!+3Eception<+Re"%
F
F
F
ADD SERVER
import Wa8a.net.?%
import Wa8a.rmi.?%
pulic class /ddSer8er
#
pulic static 8oid main!String args&)"
#
try
#
/ddSer8er1mpl addSer8er1mpl*neD /ddSer8er1mpl!"%
2aming.reind!+/ddSer8er+$addSer8er1mpl"%
F
catch!3Eception e"
#
System.out.println!+3Eception <+Re"%
F
F
F
ADD SERVERIMPL:
import Wa8a.rmi.?%
import Wa8a.rmi.ser8er.?%
pulic class /ddSer8er1mpl eEtends Unicast6emote4Wect implements /ddSer8er1ntf
#
pulic /ddSer8er1mpl!"throDs 6emote3Eception
#
F
pulic doule add!doule d,$doule d-"throDs 6emote3Eception
#
return d,Rd-%
F
F
ADDSERVERINTF:
import Wa8a.rmi.?%
pulic interface /ddSer8er1ntf eEtends 6emote
#
doule add!doule d,$doule d-"throDs 6emote3Eception%
F
OUTPUT:
RESULT:
Thus the ao8e program 6PC Das eEecuted and successfully.
EX NO: / PROGRAMS USING DNS
AIM:
To implement the program using B2S
PROGRAM:
// Cli'n$ P#!#,- : dn0%.%
#include<stdio.h>
#include<sys/stat.h>
#include<sys/types.h>
#include<sys/socket.h>
#include<arpa/inet.h>
#include<netinet/in.h>
main!"
#
struct sockaddr0in ser8er$client%
int s$n%
char ,&,(()$-&,(()%
s*socket!/F0123T$S4C50BH6/7$("%
ser8er.sin0family*/F0123T%
ser8er.sin0port*V(((%
ser8er.sin0addr.s0addr*inet0addr!+,-;.(.(.,+"%
n*si9eof!ser8er"%
printf!+>n3nter canonical address< +"%
scanf!+=s+$-"%
sendto!s$-$si9eof!-"$($!struct sockaddr ?":ser8er$n"%
rec8from!s$,$si9eof!,"$ ($2UAA$2UAA"%
printf!+=s >n+$,"%
F
// S'#('# P#!#,- : dn00.%
#include<stdio.h>
#include<sys/stat.h>
#include<sys/types.h>
#include<sys/socket.h>
#include<netinet/in.h>
#include<arpa/inet.h>
#include<string.h>
main!"
#
F1A3 ?fp%
struct sockaddr0in ser8er$client%
int s$n%
char ,&,(()$-&,(()$a&,(()%
s*socket!/F0123T$S4C50BH6/7$("%
ser8er.sin0family*/F0123T%
ser8er.sin0port*V(((%
ser8er.sin0addr.s0addr*inet0addr!+,-;.(.(.,+"%
ind!s$!struct sockaddr ?":ser8er$si9eof!ser8er""%
n*si9eof!client"%
Dhile!,"
#
strcpy!-$++"%
fp*fopen!+dns.tEt+$+r+"%
rec8from!s$,$si9eof ,$ ($!struct sockaddr ?":client$:n"%
Dhile!Qfeof!fp""
#
fscanf!fp$+=s+$a"%
if!strcmp!a$,"**("
#
fscanf!fp$+=s+$-"%
reak%
F
F
if!strcmp!-$++"**("
#
strcpy!-$+2ot found...+"%
F
fclose!fp"%
sendto!s$-$si9eof -$($!struct sockaddr ?":client$n"%
F
F
/1 2DNS.$3$"
DDD.-kNcs.tk OV.,;(.'-.-(
DDD.google.com ,O-.,LN.(.;
DDD.yahoo.com ,O-.,LN.(.,L
DDD.-kNL,N.logspot.com LL.,(-.,V.,O,
1/
O)$*)$:
T'#-in,l1: 2Cli'n$4
nnIlinuEmint J U gcc dnsc.c Ko client
nnIlinuEmint J U ./client
3nter canonical address< DDD.-kNcs.tk
OV.,;(.'-.-(
nnIlinuEmint J U ./client
3nter canonical address< DDD.-kNL,N.logspot.com
LL.,(-.,V.,O,
nnIlinuEmint J U
T'#-in,l 2: 2S'#('#4
nnIlinuEmint J U gcc dnss.c Ko ser8er
nnIlinuEmint J U ./ser8er
RESULT:
Thus the ao8e program 6PC Das eEecuted and successfully.

Das könnte Ihnen auch gefallen