40 #ifndef KUKA_RSI_HARDWARE_INTERFACE_UDP_SERVER_ 41 #define KUKA_RSI_HARDWARE_INTERFACE_UDP_SERVER_ 55 #include <sys/types.h> 56 #include <sys/socket.h> 57 #include <netinet/in.h> 58 #include <arpa/inet.h> 67 sockfd_ = socket(AF_INET, SOCK_DGRAM, 0);
69 throw std::runtime_error(
"Error opening socket: " + std::string(strerror(errno)));
71 setsockopt(
sockfd_, SOL_SOCKET, SO_REUSEADDR, (
const void *)&
optval ,
sizeof(
int));
77 throw std::runtime_error(
"Error binding socket: " + std::string(strerror(errno)));
90 tv_.tv_sec = millisecs / 1000;
91 tv_.tv_usec = (millisecs % 1000) * 1000;
101 ssize_t
send(std::string& buffer)
107 std::cout <<
"ERROR in sendto" << std::endl;
113 ssize_t
recv(std::string& buffer)
124 tv.tv_sec =
tv_.tv_sec;
125 tv.tv_usec =
tv_.tv_usec;
127 if (select(
sockfd_+1, &read_fds, NULL, NULL, &tv) < 0)
132 if (FD_ISSET(
sockfd_, &read_fds))
138 std::cout <<
"ERROR in recvfrom" << std::endl;
153 std::cout <<
"ERROR in recvfrom" << std::endl;
UDPServer(std::string host, unsigned short port)
ssize_t send(std::string &buffer)
struct sockaddr_in serveraddr_
ssize_t recv(std::string &buffer)
bool set_timeout(int millisecs)
struct sockaddr_in clientaddr_
unsigned short local_port_