Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <sys/types.h>
- #include <sys/socket.h>
- #include <netinet/in.h>
- #include <stdio.h>
- #include <errno.h>
- #include <string.h>
- #define PORT 6969
- #include <stdlib.h>
- #include <iostream>
- #include <unistd.h>
- #include <pthread.h>
- # include <sys/types.h>
- # include <sys/ipc.h>
- using namespace std;
- pthread_mutex_t m1;
- int main()
- {
- while(1){
- pthread_mutex_lock(&m1);
- int buf[2];//что будешь отправлять, буфер данных
- int sock;
- struct sockaddr_in addr;
- sock = socket(AF_INET, SOCK_DGRAM, 0);
- addr.sin_family = AF_INET;
- addr.sin_port = htons(PORT);
- addr.sin_addr.s_addr = htonl(INADDR_ANY);
- bind(sock, (struct sockaddr *) &addr, sizeof(addr));
- recv(sock, buf, 2, MSG_OOB);
- for (int i = 0; i < 2; i++)
- buf[i] = buf[i] * buf[i];
- send(sock, buf, 2, MSG_OOB);
- close(sock);
- pthread_mutex_unlock(&m1);
- return 0; }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement