Advertisement
Guest User

Untitled

a guest
Oct 17th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. #include<sys/types.h>
  2. #include<sys/socket.h>
  3. #include <stdio.h>
  4. #include <netinet/in.h>
  5. #include <netinet/ip.h>
  6. #include <string.h>
  7.  
  8. int main(){
  9. int c;
  10. struct sockaddr_in server;
  11. char string[100], oglindit[100];
  12.  
  13. c = socket(AF_INET, SOCK_STREAM, 0);
  14. if (c < 0) {
  15. printf("Eroare la crearea socketului client\n");
  16. return 1;
  17. }
  18.  
  19. memset(&server, 0, sizeof(server));
  20. server.sin_port = htons(1274);
  21. server.sin_family = AF_INET;
  22. server.sin_addr.s_addr = inet_addr("127.0.0.1");
  23.  
  24. if (connect(c, (struct sockaddr *) &server, sizeof(server)) < 0) {
  25. printf("Eroare la conectarea la server\n");
  26. return 1;
  27. }
  28.  
  29. printf("Dati sirul de caractere: ");
  30. fgets(&string, 100, stdin);
  31. uint16_t length = strlen(string);
  32. length = htons(length);
  33. send(c, &length, sizeof(length), 0);
  34. send(c, &string, strlen(string)*sizeof(char), 0);
  35. recv(c, oglindit, strlen(string), MSG_WAITALL);
  36. printf("%s\n", oglindit);
  37. close(c);
  38. return 0;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement