33 WORD wVersionRequested = MAKEWORD(2, 2);
35 WSAStartup(wVersionRequested, &wdData);
36 _socketfd = INVALID_SOCKET;
37 if((_socketfd = socket(AF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET){
40 _socketAddr.sin_family = AF_INET;
41 _socketAddr.sin_addr.s_addr = inet_addr(_ipAddr);
42 _socketAddr.sin_port = htons(_port);
43 if(connect(_socketfd, (SOCKADDR *) &_socketAddr,
sizeof(_socketAddr)) == SOCKET_ERROR){
44 std::cout <<
"client could not connect, check if server is running\n";
73 if (read_return == 0) {
92 _socketfd = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
94 std::cout <<
"socket could not be created"<<
_ipAddr<<
" port: "<<
_port<<
" \n";
104 if ( errno == EAFNOSUPPORT ){
105 std::cout <<
"inet_pton failed, try again "<<
_ipAddr<<
" port: "<<
_port<<
" \n";
111 std::cout <<
"client could not connect, check if server is running on ip "<<
_ipAddr<<
" port: "<<
_port<<
" \n";
134 std::cout <<
"Write not complete: size and length of buf written do not match\n";
144 read_return = read(
_socketfd, _buf, _size);
146 if (read_return <= 0) {
148 std::cout <<
"Read not complete. Buffer size and message length do not match. buf: " << _buf <<
" _size: " << read_return << std::endl;
163 #endif //WIN32 else LINUX virtual int disconnect()
Terminates the socket connection.
virtual ~CCdlSocket()
Destructs the object.
struct sockaddr_in _socketAddr
Structure to fill in the socket communication parameteres.
virtual int send(const void *_buf, int _size)
Sends data to the socket.
int _port
Port number of the KNI communication socket.
int _len
Length of the message.
char * _ipAddr
IP Address of the Robot or simulation environment.
virtual int recv(void *_buf, int _size)
Receives data from the socket.
CCdlSocket(char *adress, int port)
Constructs a CCdlSocket object.
int _socketfd
File handler for the socket.