clientu.c 733 B

123456789101112131415161718192021222324252627282930313233
  1. #include<stdio.h>
  2. #include<netinet/in.h>
  3. #include<sys/socket.h>
  4. #include<sys/types.h>
  5. #include<string.h>
  6. #include<unistd.h>
  7. int main()
  8. {
  9. int sd,portno,i;
  10. struct sockaddr_in cli;
  11. char msg[80],ip[80];
  12. sd=socket(AF_INET,SOCK_DGRAM,0);
  13. bzero(&cli,sizeof(cli));
  14. printf("enter the port no");
  15. scanf("%d",&portno);
  16. cli.sin_port=htons(portno);
  17. cli.sin_family=AF_INET;
  18. printf("enter the ip address");
  19. scanf("%s",ip);
  20. cli.sin_addr.s_addr=inet_addr(ip);
  21. printf("\nenter the message to send\n");
  22. scanf("%s",msg);
  23. sendto(sd,msg,80,0,(struct sockaddr*)&cli,sizeof(cli));
  24. printf("\nreply from server\n");
  25. i=sizeof(cli);
  26. recvfrom(sd,msg,80,0,(struct sockaddr*)&cli,&i);
  27. printf("%s",msg);
  28. return 0;
  29. //scanf("%s",msg);
  30. }