Advertisement
Guest User

Untitled

a guest
Dec 11th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <errno.h>
  3. #include <iostream>
  4. #include <unistd.h>
  5. #include <stdio.h>
  6. #include <sys/types.h>
  7. #include <sys/socket.h>
  8. #include <netinet/in.h>
  9. /*Сервер должен быть запущен в 1-ой консоли */
  10. #define PORT 6969
  11.  
  12. using namespace std;
  13. int sock;
  14. struct sockaddr_in addr;
  15. int buf[2];
  16. pthread_mutex_t m1, m2,m3;
  17.  
  18. int main() {
  19. while (1) {
  20.  
  21. pthread_mutex_init(&m1, PTHREAD_MUTEX_NORMAL);
  22. pthread_mutex_init(&m2, PTHREAD_MUTEX_NORMAL);
  23. pthread_mutex_init(&m3, PTHREAD_MUTEX_NORMAL);
  24. sock = socket(AF_INET, SOCK_DGRAM, 0);
  25. addr.sin_family = AF_INET;
  26. addr.sin_port = htons(PORT);
  27. addr.sin_addr.s_addr = htonl(INADDR_ANY);
  28. bind(sock, (struct sockaddr *) &addr, sizeof(addr));
  29. cout << "Первый катет" << endl;
  30. cin >> buf[0];
  31. cout << "Второй катет" << endl;
  32. cin >> buf[1];
  33.  
  34. send(sock, buf, 2, MSG_OOB);
  35. recv(sock, buf, 2, MSG_OOB);
  36. //
  37.  
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement