123456789101112131415161718192021222324252627282930313233 |
- #include<stdio.h>
- #include<netinet/in.h>
- #include<sys/socket.h>
- #include<sys/types.h>
- #include<string.h>
- #include<unistd.h>
- int main()
- {
- int sd,portno,i;
- struct sockaddr_in cli;
- char msg[80],ip[80];
- sd=socket(AF_INET,SOCK_DGRAM,0);
- bzero(&cli,sizeof(cli));
- printf("enter the port no");
- scanf("%d",&portno);
- cli.sin_port=htons(portno);
- cli.sin_family=AF_INET;
- printf("enter the ip address");
- scanf("%s",ip);
- cli.sin_addr.s_addr=inet_addr(ip);
- printf("\nenter the message to send\n");
- scanf("%s",msg);
- sendto(sd,msg,80,0,(struct sockaddr*)&cli,sizeof(cli));
- printf("\nreply from server\n");
- i=sizeof(cli);
- recvfrom(sd,msg,80,0,(struct sockaddr*)&cli,&i);
- printf("%s",msg);
- return 0;
- //scanf("%s",msg);
- }
|