skip to main |
skip to sidebar
IMPLEMENTATION OF UDP ( Universal Datagram Protocol ) Programs
IMPLEMENTATION OF UDP
PROGRAM:
CLIENT:
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define REMOTE_SERVER_PORT 1896s
#define MAX_MSG 100
int main(int argc,char*argv[])
{
int sd,rc,i;
struct sockaddr_in cliaddr,remoteservaddr;
struct hostent *h;
if(argc<3)
{
printf("Usage:%s..\n",argv[0]);
exit(1);
}
h=gethostbyname(argv[1]);
if(h==NULL)
{
printf("%s:unknown host%s\n",argv[0],argv[1]);
exit(1);
}
printf("%s:sending data to '%s'(IP:%s)\n",argv[0],h->h_name,inet_ntoa(*(struct i
n_addr*)h->h_addr_list[0]));
remoteservaddr.sin_family=h->h_addrtype;
memcpy((char*)&remoteservaddr.sin_addr.s_addr,h->h_addr_list[0],h->h_length);
remoteservaddr.sin_port=htons(REMOTE_SERVER_PORT);
sd=socket(AF_INET,SOCK_DGRAM,0);
if(sd<0)
{
printf("%s:cannot open socket\n",argv[0]);
exit(1);
}
cliaddr.sin_family=AF_INET;
cliaddr.sin_addr.s_addr=htonl(INADDR_ANY);
cliaddr.sin_port=htons(0);
rc=bind(sd,(struct sockaddr*)&cliaddr,sizeof(cliaddr));
if(rc<0)
{
printf("%s:cannot bindport\n",argv[0]);
exit(1);
}
for(i=2;i
{
rc=sendto(sd,argv[i],strlen(argv[i])+1,0,(struct sockaddr*)&remoteservaddr,sizeo
f(remoteservaddr));
if(rc<0)
{
printf("%s:cannot send data%d\n",argv[0],i-1);
close(sd);
exit(1);
}
}
return 1;
}
SERVER:
#include
#include
#include
#include
#include
#include
#include
#define LOCAL_SERVER_PORT 1896
#define MAX_MSG 100
int main(int argc,char *argv[])
{
int sd,rc,n,clilen;
struct sockaddr_in cliaddr,servaddr;
char msg[MAX_MSG];
sd=socket(AF_INET,SOCK_DGRAM,0);
if(sd<0)
{
printf("%s:cannot open socket\n",argv[0]);
exit(1);
}
servaddr.sin_family=AF_INET;
servaddr.sin_addr.s_addr=htonl(INADDR_ANY);
servaddr.sin_port=htons(LOCAL_SERVER_PORT);
rc=bind(sd,(struct sockaddr*)&servaddr,sizeof(servaddr));
if(rc<0)
{
printf("%s:cannot bind port number %d\n",argv[0],LOCAL_SERVER_PORT);
exit(1);
}
printf("%s:waiting for data on port UDP%u\n",argv[0],LOCAL_SERVER_PORT);
while(1)
{
memset(msg,0x0,MAX_MSG);
clilen=sizeof(cliaddr);
n=recvfrom(sd,msg,MAX_MSG,0,(struct sockaddr*)&cliaddr,&clilen);
if(n<0)
{
printf("%s:cannot receive data\n",argv[0]);
continue;
}
printf("%s:from%s:UDP%u:%s\n",argv[0],inet_ntoa(cliaddr.sin_addr),ntohs(cliaddr.
sin_port),msg);
}
return 0;
}
OUTPUT:
IN SERVER:
[testciet @linuxcentre ~]$ ./a.out
./a.out:waiting for data on port UDP1896
./a.out:from127.0.0.1:UDP32771:hi ……
IN CLIENT:
[testciet@linuxcentre ~]$ ./a.out localhost hi ……
./a.out:sending data to 'linuxcentre'(IP:127.0.0.1)
CIET college Programs,LAB Programs for Engineering Students,Computer Networks LAB Programs,Remoboys,karthik,Remokn,Student3k,TCP programs source code
Blog Archive
-
▼
2014
(4835)
-
▼
September
(92)
- Sexy Arm Tattoo
- Be Craze Generation with Lower Back Tattoo
- Sexy Lower Back Tribal New Tattoo
- Sexy Flower Tattoo
- Lettering Styles For Text Tattoos
- Girl Tattoo Picture
- வானம்-எக்ஸ்க்ளூசிவ் படங்கள்!
- அட... திருந்துங்கப்பா...!!!
- Jinxi's Interview With Tattoo Artist Matt Griffith
- The Case for Dragon Tattoo Designs
- Tamara Geraldine Tattoo
- Julia Peres Tattoo
- Tattoo artist Friday Jones
- CIET(Coimbatore Institute of Engineering and Infor...
- IMPLEMENTATION OF KNAPSACK ALGORITHM PROGRAM
- IMPLEMENTATION OF PRIMS ALGORITHM
- IMPLEMENTATION OF KRUSKALS ALGORITHM
- IMPLEMENTATION OF NON RECURSIVE BINARY SEARCH TREE...
- IMPLEMENTATION OF RECURSIVE BINARY SEARCH TREE PRO...
- IMPLEMENTATION OF HEAP SORT Programs
- IMPLEMENTATION OF SELECTION SORT PROGRAMs
- IMPLEMENTATION OF QUICK SORT PROGRAM
- IMPLEMENTATION OF MERGE SORT
- IMPLEMENTATION OF SHORTEST PATH ALGORITHM
- IMPLEMENTATION OF SLIDING WINDOW PROTOCOL
- IMPLEMENTATION OF UDP ( Universal Datagram Protoco...
- IMPLEMENTATION OF TCP (Transmission Control Protoc...
- Aamir khan wallpapers free
- Ajay devgan wallpaper photo image pictures Stills
- Tamil actress asin wallpapers download
- Wwe John Cena Wallpapers free image photo pictures...
- Free download John Cena wallpapers
- free john cena wallpapers
- WWE Super Stars Wallpapers
- Wwe Money In The Bank Ladder Match Wallpapers,Phot...
- WWE Superstar Batista Wallpaper,Photo,Still,Image
- Wwe The Big Show Profile And Biodata
- WWE Superstar Undertaker Wallpaper,Photo,Still,Image
- Wwe The Undertaker Profile And Biodata
- Wwe Edge Profile And Biodata
- Wwe Rey Mysterio Profile And Biodata
- WWE Superstar Rey Mysterio Wallpaper,Photo,Still,I...
- Download Hindu God Hanuman Wallpapers
- Download Hindu God Krishna Wallpapers
- Download Hindu God Siva Wallpapers
- Download Hindu God Saraswati Wallpapers
- Download Hindu God Lakshmi Wallpapers
- India vs Australia Time Table,India vs Australia L...
- Latest Beach Wallpapers
- Super Car Wallpapers
- Super Natural Wallpapers
- Amazing Sky Wallpapers
- Love Wallpapers,Photos,Images And Stills
- Prabhu Deva and Nayantara Spotted at South Scope A...
- kaavalan Movie Release Date
- Osaka tattoo artist
- Perfect Honeymoon Tips: How to enjoy it?
- Dating Rules: For a successful romantic encounters
- Best Love Poems For Your Girlfriend
- ICC Cricket Ratings | Test | ODI | Test Match Rank...
- ICC Cricket World Cup 2011 schedule
- 100 Best companies For You
- sachin Tendulkar's records
- Indian Avatar Is Mr sorry sorry Dr Vijay Is Here !
- Pakistan match-fixing scandal
- Endhiran latest News
- Intel Core i3 530 processor News
- Thala Ajith's Mankatha Stills Latest Trailer Still...
- Triple H The King Of Kings wallpapers HHH
- Tattoo artist Kat Von D
- wwe superstars wallpapers, wwe batista wallpapers ...
- Bruce Davis Tattoo
- The Godmother of Tattoo
- Spring 2010 MBFW
- Tattoo Artist Moto Clube Faro
- Mike Zaher Tattoo
- Mike Monsoor Tattoo
- Lorenzo Mata Tattoo
- Brigham Harwell Tattoo
- Alyssa Milano Tattoos
- Style Tokyo Tattoo Art
- Katy Perry Tattoos
- Belly button cartoon tattoo
- Tattoo Artist Genaro David Gallegos Brass Knuckles
- Vegas wins with tattoos for soccer moms
- Tattoo Artist Shrume
- Beauty wing tattoo picture 2010 for sexy girls
- Shaquille O'Neal Tattoos
- Hot Girl Tattoos
- Harley Davidson Tattoo Design
- Jon Reed Tattoo
- The Tattoo Artist
0 komentar:
Posting Komentar