7 #include <sys/socket.h>
9 #include <netinet/in.h>
20 #define MAXSIZE 1024*1024
31 struct addrinfo hints;
32 memset(&hints, 0,
sizeof(
struct addrinfo));
34 hints.ai_family = AF_INET;
35 struct addrinfo *result;
38 sprintf(port_str,
"%d",
PORT);
40 int status = getaddrinfo(_hostname.c_str(), port_str,
47 cerr << _hostname <<
": " << gai_strerror(status) << endl;
52 struct sockaddr_in* ipv4;
53 ipv4 = (
struct sockaddr_in*)result->ai_addr;
67 if ( (_sockfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0 )
69 perror(
"socket creation failed");
73 memcpy(&_serveraddr, ipv4,
sizeof(*ipv4));
81 _serveraddr.sin_family = AF_INET;
82 _serveraddr.sin_port = htons(
PORT);
88 if ( _sockfd > 0) close(_sockfd);
94 int sendbuffer[2] = {0};
97 if (_verbosity) cout <<
"requesting event " << eventnumber << endl;
101 sendbuffer[0] = eventnumber;
104 sendto(_sockfd, (
const char *)sendbuffer, 2*
sizeof(
int),
105 0, (
const struct sockaddr *) &_serveraddr,
106 sizeof(_serveraddr));
109 int n = recvfrom(_sockfd, (
char *)buffer,
MAXSIZE*
sizeof(
int),
110 MSG_WAITALL, (
struct sockaddr *) &_serveraddr,
113 if (_verbosity) cout <<
" received " << n <<
" bytes" << std::endl;
116 if (_verbosity) std::cout <<
"Event " << sendbuffer[0] <<
" not found" << endl;