client.c 691 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include<string.h>
  4. #include<unistd.h>
  5. #include<arpa/inet.h>
  6. #define port 8081
  7. int main()
  8. {
  9. int sockfd;
  10. struct sockaddr_in client;
  11. if((sockfd=socket(AF_INET,SOCK_STREAM,0))<0)
  12. perror("socket failed\n");
  13. client.sin_family = AF_INET;
  14. client.sin_addr.s_addr = inet_addr("127.0.0.1");
  15. client.sin_port = htons(port);
  16. if(connect(sockfd,(struct sockaddr*)&client,sizeof(client))<0)
  17. perror("connection failed\n");
  18. else
  19. printf("connected successfully\n");
  20. while(1)
  21. {
  22. char s[20];
  23. printf("enter the data to send\n");
  24. scanf("%s",s);
  25. send(sockfd,(char*)s,strlen(s),0);
  26. }
  27. }