Advertisement
Guest User

Untitled

a guest
Dec 11th, 2018
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. #include <iostream>
  2. #include <sys/types.h>
  3. #include <sys/socket.h>
  4. #include <netinet/in.h>
  5. #include <stdio.h>
  6. #include <errno.h>
  7. #include <string.h>
  8. #define PORT 6969
  9. #include <stdlib.h>
  10. #include <iostream>
  11. #include <unistd.h>
  12. #include <pthread.h>
  13. # include <sys/types.h>
  14. # include <sys/ipc.h>
  15.  
  16. using namespace std;
  17.  
  18. pthread_mutex_t m1;
  19.  
  20. int main()
  21. {
  22. while(1){
  23. pthread_mutex_lock(&m1);
  24. int buf[2];//что будешь отправлять, буфер данных
  25. int sock;
  26. struct sockaddr_in addr;
  27. sock = socket(AF_INET, SOCK_DGRAM, 0);
  28. addr.sin_family = AF_INET;
  29. addr.sin_port = htons(PORT);
  30. addr.sin_addr.s_addr = htonl(INADDR_ANY);
  31. bind(sock, (struct sockaddr *) &addr, sizeof(addr));
  32.  
  33. recv(sock, buf, 2, MSG_OOB);
  34.  
  35.  
  36. for (int i = 0; i < 2; i++)
  37. buf[i] = buf[i] * buf[i];
  38. send(sock, buf, 2, MSG_OOB);
  39. close(sock);
  40. pthread_mutex_unlock(&m1);
  41.  
  42. return 0; }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement