client.c 738 B

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