|
|
@ -16,7 +16,7 @@ address specified in the constructor, and will throw an exception if that fails.
|
|
|
|
The exception thrown is an integer, that corresponds to the errno returned by the failing
|
|
|
|
The exception thrown is an integer, that corresponds to the errno returned by the failing
|
|
|
|
function. This enables a client to 'catch' the thrown exception, and print the corresponding
|
|
|
|
function. This enables a client to 'catch' the thrown exception, and print the corresponding
|
|
|
|
error message using strerror().
|
|
|
|
error message using strerror().
|
|
|
|
*/
|
|
|
|
This function also sets a timeout of 100ms for UDP sockets. */
|
|
|
|
|
|
|
|
|
|
|
|
void Client::create_socket() {
|
|
|
|
void Client::create_socket() {
|
|
|
|
Sock::create_socket();
|
|
|
|
Sock::create_socket();
|
|
|
@ -24,6 +24,12 @@ void Client::create_socket() {
|
|
|
|
if (this->sock_fd < 0) {
|
|
|
|
if (this->sock_fd < 0) {
|
|
|
|
throw (this->sock_fd * -1);
|
|
|
|
throw (this->sock_fd * -1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// if (protocol == ES_UDP) {
|
|
|
|
|
|
|
|
// struct timeval tv;
|
|
|
|
|
|
|
|
// tv.tv_sec = 0;
|
|
|
|
|
|
|
|
// tv.tv_usec = 10000;
|
|
|
|
|
|
|
|
// setsockopt(this->sock_fd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv));
|
|
|
|
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Sends given data to the peer socket. This method is overriden, because a TCP
|
|
|
|
/* Sends given data to the peer socket. This method is overriden, because a TCP
|
|
|
@ -39,11 +45,17 @@ void Client::sendAll(std::string to_send) {
|
|
|
|
/* Receives data from peer socket, and returns it. See above for better
|
|
|
|
/* Receives data from peer socket, and returns it. See above for better
|
|
|
|
explanation of why this method is overriden. */
|
|
|
|
explanation of why this method is overriden. */
|
|
|
|
|
|
|
|
|
|
|
|
std::string Client::recvAll() {
|
|
|
|
char* Client::recvAll() {
|
|
|
|
this->other_socket = this->sock_fd;
|
|
|
|
this->other_socket = this->sock_fd;
|
|
|
|
return Sock::recvAll();
|
|
|
|
return Sock::recvAll();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Same as function above, but calls Sock::recvAllNB() */
|
|
|
|
|
|
|
|
char* Client::recvAllNB() {
|
|
|
|
|
|
|
|
this->other_socket = this->sock_fd;
|
|
|
|
|
|
|
|
return Sock::recvAllNB();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Returns the type of socket based on the global constants set in sock.hpp */
|
|
|
|
/* Returns the type of socket based on the global constants set in sock.hpp */
|
|
|
|
int Client::get_type() {
|
|
|
|
int Client::get_type() {
|
|
|
|
return SOCK_CLIENT;
|
|
|
|
return SOCK_CLIENT;
|
|
|
|