diff options
author | hugues <hugues@0f7e0d06-a6f9-0310-a55f-d5f984f55e4c> | 2006-03-25 15:07:51 +0000 |
---|---|---|
committer | Hugues Hiegel <hugues@hiegel.fr> | 2008-03-18 10:06:55 +0100 |
commit | 56cc59cf44ec64440ba4d1c0d005196195c758e6 (patch) | |
tree | 0e4bc431438a05c2e32b8703a8c79dcbf26a7cbf /trunk/glagen/algo_distribue/network/Client.hh | |
parent | d49be924baa2759aefa5b5311a35adf50db48e12 (diff) |
git-svn-id: file:///usr/local/opt/svn/repos/glagen@12 0f7e0d06-a6f9-0310-a55f-d5f984f55e4c
Diffstat (limited to 'trunk/glagen/algo_distribue/network/Client.hh')
-rw-r--r-- | trunk/glagen/algo_distribue/network/Client.hh | 113 |
1 files changed, 0 insertions, 113 deletions
diff --git a/trunk/glagen/algo_distribue/network/Client.hh b/trunk/glagen/algo_distribue/network/Client.hh deleted file mode 100644 index 923b83e..0000000 --- a/trunk/glagen/algo_distribue/network/Client.hh +++ /dev/null @@ -1,113 +0,0 @@ -// Classe Client - -#ifndef CLIENT_HH_ -# define CLIENT_HH_ - -#include <list> -#include <iostream> -#include <string> -#include <stdio.h> -#include <sys/socket.h> -#include <netinet/in.h> -#include <signal.h> -#include <netdb.h> -#include <assert.h> -#include <unistd.h> - -#include "data/Data.hh" - -class Client -{ -public: - Client(char* host, const int& port) - { - char *c; - int sock; - struct sockaddr_in sa; - long addr; - struct hostent *host_info; - - if ((host_info = gethostbyname(host)) == 0) - this->error(); - c = host_info->h_addr; - addr = c[0] << 24 | c[1] << 16 | c[2] << 8 | c[3]; - if ((sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) == -1) - this->error(); - sa.sin_family = AF_INET; - sa.sin_port = htons(port); - sa.sin_addr.s_addr = htonl(addr); - if (connect(sock, (struct sockaddr *)&sa, sizeof (sa)) == -1) - this->error(); - _fd_server = sock; - } - - void error() - { - std::cerr << "Error client : "; - perror(""); - exit(errno); - } - - template <class TYPEDATA> - void send_data(const Data<TYPEDATA>& data) const - { - data.send(_fd_server); - } - - template <class TYPEDATA> - void received_data(Data<TYPEDATA>& data) - { - data.receive(_fd_server); - } - - void wait_signal() - { - unsigned char sig = 0; - read(_fd_server, &sig, sizeof(unsigned char)); - if (sig != 42) - { - std::cout << "Erreur de transmission" << std::endl; - exit(1); - } - std::cout << "En communication avec le serveur..." << std::endl; - } - - void send_signal() - { - unsigned char sig = 42; - write(_fd_server, &sig, sizeof(unsigned char)); - } - - int do_select() - { - fd_set rd; - char buf[256]; - int n; - - FD_ZERO(&rd); - FD_SET(0, &rd); - FD_SET(_fd_server, &rd); - if (select(_fd_server + 1, &rd, 0, 0, 0) == -1) - this->error(); - if (FD_ISSET(_fd_server, &rd)) - { - n = read(_fd_server, buf, 150); - if (n <= 0) - return (1); - write(1, buf, n); - fflush(0); - } - if (FD_ISSET(0, &rd)) - { - n = read(0, buf, 100); - write(_fd_server, buf, n); - } - return (0); - } - - -private: - int _fd_server; -}; - -#endif // CLIENT_HH_ |