summaryrefslogtreecommitdiff
path: root/tags/START/glagen/algo_distribue/network
diff options
context:
space:
mode:
Diffstat (limited to 'tags/START/glagen/algo_distribue/network')
-rw-r--r--tags/START/glagen/algo_distribue/network/Client.cc1
-rw-r--r--tags/START/glagen/algo_distribue/network/Client.hh113
-rw-r--r--tags/START/glagen/algo_distribue/network/Makefile62
-rw-r--r--tags/START/glagen/algo_distribue/network/Server.cc1
-rw-r--r--tags/START/glagen/algo_distribue/network/Server.hh218
-rw-r--r--tags/START/glagen/algo_distribue/network/data/Data.cc1
-rw-r--r--tags/START/glagen/algo_distribue/network/data/Data.hh78
-rw-r--r--tags/START/glagen/algo_distribue/network/data/Data_exemple.cc1
-rw-r--r--tags/START/glagen/algo_distribue/network/data/Data_exemple.hh66
-rw-r--r--tags/START/glagen/algo_distribue/network/data/Data_string.cc1
-rw-r--r--tags/START/glagen/algo_distribue/network/data/Data_string.hh60
-rw-r--r--tags/START/glagen/algo_distribue/network/main_client.cc54
-rw-r--r--tags/START/glagen/algo_distribue/network/main_server.cc73
13 files changed, 0 insertions, 729 deletions
diff --git a/tags/START/glagen/algo_distribue/network/Client.cc b/tags/START/glagen/algo_distribue/network/Client.cc
deleted file mode 100644
index 23ccb2c..0000000
--- a/tags/START/glagen/algo_distribue/network/Client.cc
+++ /dev/null
@@ -1 +0,0 @@
-#include "Client.hh"
diff --git a/tags/START/glagen/algo_distribue/network/Client.hh b/tags/START/glagen/algo_distribue/network/Client.hh
deleted file mode 100644
index 923b83e..0000000
--- a/tags/START/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_
diff --git a/tags/START/glagen/algo_distribue/network/Makefile b/tags/START/glagen/algo_distribue/network/Makefile
deleted file mode 100644
index 18878df..0000000
--- a/tags/START/glagen/algo_distribue/network/Makefile
+++ /dev/null
@@ -1,62 +0,0 @@
-##
-## Makefile for in
-##
-## Made by meng-tih lam
-## Login <lam_m@epita.fr>
-##
-## Started on Thu Feb 7 19:08:57 2002 meng-tih lam
-
-##
-
-NAME_SERVER = glagen_server
-NAME_CLIENT = glagen_client
-SRC_DATA = data/Data.cc\
- data/Data_exemple.cc\
- data/Data_string.cc
-SRC_SERVER = Server.cc main_server.cc
-SRC_CLIENT = Client.cc main_client.cc
-
-OBJ_SERVER = $(SRC:.cc=.o) $(SRC_SERVER:.cc=.o)
-OBJ_CLIENT = $(SRC:.cc=.o) $(SRC_CLIENT:.cc=.o)
-
-ARCHI_i586 = -g2 -Wall -W -Werror -O3
-ARCHI_NetBSD = -g2 -Wall -W -Werror -O3 -I/usr/X11R6/include
-ARCHI_sun4 = -g2 -Wall -W -Werror -O3
-ARCHI_alpha = -g2 -Wall -W -Werror -O3
-
-LIB_i586 = -lc
-LIB_NetBSD = -L/usr/pkg/lib -L/usr/X11R6/lib -lGL -lGLU -lglut -lc
-LIB_alpha =
-LIB_sun4 = -lsocket -lnsl
-
-CPPFLAGS = -I.
-CC = g++
-RM = rm -f
-
-.PHONY: all clean deps
-
-all: server client
-
-server: $(NAME_SERVER)
-
-client: $(NAME_CLIENT)
-
-$(NAME_SERVER): $(OBJ_SERVER)
- $(CC) -o $(NAME_SERVER) $(CFLAGS) $(OBJ_SERVER)\
- $(LIB_${HOSTTYPE}) $(ARCHI_${HOSTTYPE})
-
-$(NAME_CLIENT): $(OBJ_CLIENT)
- $(CC) -o $(NAME_CLIENT) $(CFLAGS) $(OBJ_CLIENT)\
- $(LIB_${HOSTTYPE}) $(ARCHI_${HOSTTYPE})
-
-.cc.o:
- $(CC) $(ARCHI_${HOSTTYPE}) $(CPPFLAGS) -c $<
-
-clean:
- $(RM) $(OBJ_SERVER) $(OBJ_CLIENT) $(NAME_SERVER) $(NAME_CLIENT)\
- *~ \#*\#
-
-deps:
- makedepend $(SRC) 2>/dev/null
-
-re: clean all
diff --git a/tags/START/glagen/algo_distribue/network/Server.cc b/tags/START/glagen/algo_distribue/network/Server.cc
deleted file mode 100644
index 63f45ff..0000000
--- a/tags/START/glagen/algo_distribue/network/Server.cc
+++ /dev/null
@@ -1 +0,0 @@
-#include "Server.hh"
diff --git a/tags/START/glagen/algo_distribue/network/Server.hh b/tags/START/glagen/algo_distribue/network/Server.hh
deleted file mode 100644
index fdfecb4..0000000
--- a/tags/START/glagen/algo_distribue/network/Server.hh
+++ /dev/null
@@ -1,218 +0,0 @@
-// Classe Server
-
-#ifndef SERVER_HH_
-# define SERVER_HH_
-
-#include <list>
-#include <iostream>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <signal.h>
-#include <poll.h>
-#include <stdio.h>
-#include <unistd.h>
-#include <errno.h>
-
-#include <assert.h>
-#include "data/Data.hh"
-
-extern char gl_handle;
-
-extern void signal_alarm(int);
-
-template<class TYPEDATA> class Data;
-
-class Server
-{
-public:
- Server(const int& port, const unsigned int& nb_client_max)
- {
- _port = port;
- _client_max = nb_client_max;
- _fd = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
- _sock_in = new struct sockaddr_in;
- _sock_in->sin_family = PF_INET;
- _sock_in->sin_port = htons(port);
- _sock_in->sin_addr.s_addr = INADDR_ANY;
- if ((bind(_fd, (struct sockaddr *)_sock_in, sizeof (*_sock_in)) == -1)
- || (listen(_fd, 5) == -1))
- this->error();
- std::cout << "Server started. Listening on port " << _port << std::endl;
- _fd_client = new std::list<int>;
- this->start_signal();
- this->start();
- }
-
- void start()
- {
- int fd_client;
- socklen_t len;
- struct sockaddr_in sock_client;
-
- len = sizeof (struct sockaddr_in);
- while (gl_handle != -1 && this->_fd_client->size() < _client_max)
- {
- fd_client = 0;
- if ((fd_client = accept(this->_fd,
- (struct sockaddr *)&(sock_client), &len)) > 0)
- gl_handle = gl_handle | 2;
- std::list<int> list_fd;
- if (2 == (gl_handle & 2))
- {
- this->accept_client(fd_client);
- this->send_signal(fd_client);
- std::cout << "Number of connected clients :"
- << this->_fd_client->size() << std::endl;
- }
- gl_handle = 0;
- this->test_client();
- }
- }
-
- void test_client()
- {
- if (_fd_client->size())
- {
- std::list<int>::const_iterator fd_client_tmp;
- std::list<int>::const_iterator fd_client = _fd_client->begin();
- int i = 0;
- while (fd_client != _fd_client->end())
- {
- i++;
- char c = 0;
- errno = 0;
- fd_client_tmp = fd_client;
- read(*fd_client, &c, sizeof(char));
- ++fd_client;
- if (errno == 0)
- this->remove_client(*fd_client_tmp);
- }
- }
- }
-
- void error()
- {
- std::cerr << "Error server : ";
- perror("");
- exit(errno);
- }
-
- void remove_client(const int& fd)
- {
- _fd_client->remove(fd);
- std::cout << "Client in the file descriptor : " << fd
- << " are disconnected" << std::endl;
- std::cout << "Number of connected clients :"
- << this->_fd_client->size() << std::endl;
- }
-
- void wait_signal(std::list<int>& list_fd) // retourne la liste des files descriptors a lire
- {
- struct pollfd poll_fd[_fd_client->size()];
- std::list<int>::const_iterator fd = _fd_client->begin();
- for (int i = 0; fd != _fd_client->end(); ++fd, ++i)
- {
- poll_fd[i].fd = *fd;
- poll_fd[i].events = POLLIN;
- }
- if (poll(poll_fd, _fd_client->size(), 0) < 0)
- assert(0);
- for (unsigned int i = 0; i < _fd_client->size(); ++i)
- if (poll_fd[i].revents != 0)
- {
- unsigned char sig = 0;
- unsigned int length = 0;
- do
- {
- errno = 0;
- length = read(poll_fd[i].fd, &sig, sizeof(unsigned char));
- }
- while (errno == 4);
- if (errno)
- {
- perror("");
- exit(errno);
- }
- if (length == 0)
- remove_client(poll_fd[i].fd);
- else
- if (sig == 42)
- {
- list_fd.push_back(poll_fd[i].fd);
- std::cout << "Reception signal sur le file descriptor :"
- << poll_fd[i].fd << std::endl;
- }
- else
- {
- std::cout << "Erreur de reception sur le file descriptor :"
- << poll_fd[i].fd << std::endl;
- exit(2);
- }
- poll_fd[i].revents = 0;
- }
- }
-
- void send_signal(const int& fd)
- {
- unsigned char sig = 42;
- write(fd, &sig, sizeof(unsigned char));
- }
-
- void start_signal()
- {
- struct sigaction alarm;
-
- alarm.sa_handler = signal_alarm;
- alarm.sa_flags = 0;
- sigemptyset(&(alarm.sa_mask));
- sigaddset(&(alarm.sa_mask), SIGALRM);
- sigaction(SIGALRM, &alarm, 0);
- ualarm(1, 100000);
- }
-
- template<class TYPEDATA>
- void send_data(const int& fd, const Data<TYPEDATA>& data)
- {
- data.send(fd);
- }
-
- template<class TYPEDATA>
- void send_data(const Data<TYPEDATA>& data,
- const std::list<int>& fd_client)
- {
- std::list<int>::const_iterator fd = fd_client.begin();
- for (; fd != fd_client.end(); ++fd)
- data.send(*fd);
- }
-
- template<class TYPEDATA>
- void received_data(Data<TYPEDATA>& data, const std::list<int>& fd_client)
- {
- std::list<int>::const_iterator fd = fd_client.begin();
- for (; fd != fd_client.end(); ++fd)
- data.receive(*fd);
- }
-
- void accept_client(const int& fd)
- {
- std::cout << "Client connected on file descriptor: " << fd << std::endl;
- _fd_client->push_back(fd);
- }
-
- int get_fd() const { return (_fd); }
-
- int get_port() const { return (_port); }
-
- std::list<int>* get_list_fd() const { return (_fd_client); }
-
- unsigned int get_nb_client() const { return (_fd_client->size()); }
-
-private:
- std::list<int> *_fd_client;
- struct sockaddr_in *_sock_in;
- int _port;
- unsigned int _client_max;
- int _fd;
-};
-
-#endif // SERVER_HH_
diff --git a/tags/START/glagen/algo_distribue/network/data/Data.cc b/tags/START/glagen/algo_distribue/network/data/Data.cc
deleted file mode 100644
index d3bbe6a..0000000
--- a/tags/START/glagen/algo_distribue/network/data/Data.cc
+++ /dev/null
@@ -1 +0,0 @@
-#include "Data.hh"
diff --git a/tags/START/glagen/algo_distribue/network/data/Data.hh b/tags/START/glagen/algo_distribue/network/data/Data.hh
deleted file mode 100644
index 3b630ff..0000000
--- a/tags/START/glagen/algo_distribue/network/data/Data.hh
+++ /dev/null
@@ -1,78 +0,0 @@
-// Classe Data
-
-// Dans le TYPEDATA, il faut l'implementation de toString (retourne un string)
-// et de type (retourne unsigned short int)
-
-// Type 0: char
-// Type 1: unsigned char
-// Type 2: int
-// Type 3: unsigned int
-// Type 4: short int
-// Type 5: unsigned short int
-// Type 6: long int
-// Type 7: unsigned long int
-// Type 8: float
-// Type 9: double
-// Type 10: long double
-
-#ifndef DATA_HH_
-# define DATA_HH_
-
-#include <list>
-#include <iostream>
-#include <stdio.h>
-
-#include <errno.h>
-
-template<class TYPEDATA> class Data
-{
-public:
- Data() : _data(new std::list<TYPEDATA>) {};
-
- Data(std::list<TYPEDATA>* data) : _data(data) {};
-
- void error()
- {
- perror("");
- exit(errno);
- }
-
- void add_data(const TYPEDATA& data) { _data->push_back(data); };
-
- void send(const int& fd) const
- {
- std::list<TYPEDATA>::iterator data = _data->begin();
- unsigned int size = _data->size();
- std::cout << "Taille a ecrire:" << size << std::endl;
- write(fd, &size, sizeof(unsigned int));
- for (; data != _data->end(); ++data)
- data->write_data(fd);
- }
-
- void receive(const int& fd)
- {
- unsigned int size = 0;
- do
- {
- errno = 0;
- read(fd, &size, sizeof(unsigned int));
- }
- while(errno == 4);
- if (errno)
- this->error();
- std::cout << "Taille lu: " << size << std::endl;
- TYPEDATA data;
- for (unsigned int i = 0; i < size; ++i)
- {
- data.read_data(fd);
- _data->push_back(data);
- }
- }
-
- std::list<TYPEDATA>* get_data() { return (_data); }
-
-private:
- std::list<TYPEDATA>* _data;
-};
-
-#endif // DATA_HH_
diff --git a/tags/START/glagen/algo_distribue/network/data/Data_exemple.cc b/tags/START/glagen/algo_distribue/network/data/Data_exemple.cc
deleted file mode 100644
index 9578493..0000000
--- a/tags/START/glagen/algo_distribue/network/data/Data_exemple.cc
+++ /dev/null
@@ -1 +0,0 @@
-#include "Data_exemple.hh"
diff --git a/tags/START/glagen/algo_distribue/network/data/Data_exemple.hh b/tags/START/glagen/algo_distribue/network/data/Data_exemple.hh
deleted file mode 100644
index ca1291b..0000000
--- a/tags/START/glagen/algo_distribue/network/data/Data_exemple.hh
+++ /dev/null
@@ -1,66 +0,0 @@
-// Classe Data_exemple
-
-// Un exemple sur un point de coordonnees 3D
-
-#ifndef DATA_EXEMPLE_HH_
-# define DATA_EXEMPLE_HH_
-
-#include <iostream>
-#include <unistd.h> // Pour write/read
-
-#include <errno.h>
-
-class Data_exemple
-{
-public:
- Data_exemple() : _x(0), _y(0), _z(0) {};
- Data_exemple(int x, int y, int z) : _x(x), _y(y), _z(z) {};
-
- void write_data(const int& fd) const
- {
- std::cout << "Donnees envoyes au serveur" << std::endl;
- std::cout << _x << std::endl;
- std::cout << _y << std::endl;
- std::cout << _z << std::endl;
- write(fd, &_x, sizeof(int));
- write(fd, &_y, sizeof(int));
- write(fd, &_z, sizeof(int));
- }
-
- void read_data(const int& fd)
- {
- do
- {
- errno = 0;
- read(fd, &_x, sizeof(int));
- }
- while (errno == 4);
-
- do
- {
- errno = 0;
- read(fd, &_y, sizeof(int));
- }
- while (errno == 4);
-
- do
- {
- errno = 0;
- read(fd, &_z, sizeof(int));
- }
- while (errno == 4);
-
- std::cout << "Reception message sur le file descriptor :" << fd
- << std::endl;
- std::cout << _x << std::endl;
- std::cout << _y << std::endl;
- std::cout << _z << std::endl;
- }
-
-private:
- int _x;
- int _y;
- int _z;
-};
-
-#endif // DATA_EXEMPLE
diff --git a/tags/START/glagen/algo_distribue/network/data/Data_string.cc b/tags/START/glagen/algo_distribue/network/data/Data_string.cc
deleted file mode 100644
index 9578493..0000000
--- a/tags/START/glagen/algo_distribue/network/data/Data_string.cc
+++ /dev/null
@@ -1 +0,0 @@
-#include "Data_exemple.hh"
diff --git a/tags/START/glagen/algo_distribue/network/data/Data_string.hh b/tags/START/glagen/algo_distribue/network/data/Data_string.hh
deleted file mode 100644
index a395725..0000000
--- a/tags/START/glagen/algo_distribue/network/data/Data_string.hh
+++ /dev/null
@@ -1,60 +0,0 @@
-#ifndef DATA_STRING_HH_
-# define DATA_STRING_HH_
-
-#include <iostream>
-#include <string>
-#include <unistd.h> // Pour write/read
-
-#include <errno.h>
-
-class Data_string
-{
-public:
- Data_string() : _str("") {};
- Data_string(const string& str) : _str(str) {};
-
- void write_data(const int& fd) const
- {
-
- std::cout << "Donnees envoyes" << std::endl << _str << std::endl;
- unsigned int size = _str.size();
- write(fd, &size, sizeof(unsigned int));
- for (unsigned int i = 0; i < size; ++i)
- {
- char car = _str[i];
- write(fd, &car, sizeof(char));
- }
- }
-
- void read_data(const int& fd)
- {
- unsigned int size = 0;
- do
- {
- errno = 0;
- read(fd, &size, sizeof(size));
- }
- while (errno == 4);
-
- _str = "";
- for (unsigned int i = 0; i < size; ++i)
- {
- char car;
- do
- {
- errno = 0;
- read(fd, &car, sizeof(char));
- }
- while (errno == 4);
- _str += car;
- }
-
- std::cout << "Reception message sur le file descriptor :" << fd
- << std::endl << _str << std::endl;
- }
-
-private:
- string _str;
-};
-
-#endif // DATA_STRING
diff --git a/tags/START/glagen/algo_distribue/network/main_client.cc b/tags/START/glagen/algo_distribue/network/main_client.cc
deleted file mode 100644
index 66cb083..0000000
--- a/tags/START/glagen/algo_distribue/network/main_client.cc
+++ /dev/null
@@ -1,54 +0,0 @@
-// Main du client
-
-#include <unistd.h>
-#include <assert.h>
-#include "Client.hh"
-#include "data/Data_exemple.hh"
-#include "data/Data_string.hh"
-
-void help(char *prog_name)
-{
- std::cout << prog_name << " [hostname] [port]" << std::endl;
- exit(0);
-}
-
-void check_args(int argc, char **argv)
-{
- int current;
-
- if (argc != 3)
- {
- std::cerr << "Error client : Error parameters" << std::endl;
- help(argv[0]);
- }
- for (current = 0; argv[2][current] != '\0'; current++)
- if (argv[2][current] < '0' || argv[2][current] > '9')
- {
- std::cerr << "Error client : Error parameters" << std::endl;
- help(argv[0]);
- }
-}
-
-int main(int argc, char **argv)
-{
- check_args(argc, argv);
- Client client(argv[1], atoi(argv[2]));
-// Data<Data_exemple> data;
-// data.add_data(Data_exemple(10, 11, 13));
-// data.add_data(Data_exemple(1, 4, 81));
- client.wait_signal();
-// client.send_signal();
-// client.send_data(data);
-
-// Data<Data_string> data_string;
-// client.received_data(data_string);
-
- // On devrait implementer un numero a chaque classe associe
- // Je fais ca pour l'instant comme si on connait deja le type de classe
- // c'est juste pour tester
- Data<Data_string> data_string;
- client.received_data(data_string);
-
- while (0 == client.do_select());
- return (0);
-}
diff --git a/tags/START/glagen/algo_distribue/network/main_server.cc b/tags/START/glagen/algo_distribue/network/main_server.cc
deleted file mode 100644
index 4fafd09..0000000
--- a/tags/START/glagen/algo_distribue/network/main_server.cc
+++ /dev/null
@@ -1,73 +0,0 @@
-// Main du reseau server
-
-#include <assert.h>
-#include "Server.hh"
-#include "data/Data_exemple.hh"
-#include "data/Data_string.hh"
-
-char gl_handle;
-
-void help(char *prog_name)
-{
- std::cout << prog_name << " [port]" << std::endl;
- exit(0);
-}
-
-void signal_alarm(int)
-{
- gl_handle = gl_handle | 1;
-}
-
-void check_args(int argc, char *argv1, char *argv2)
-{
- int current;
-
- if (argc != 2)
- {
- std::cerr << "Error server : Error parameters" << std::endl;
- help(argv1);
- }
- for (current = 0; argv2[current] != '\0'; current++)
- if (argv2[current] < '0' || argv2[current] > '9')
- {
- std::cerr << "Error server : Error parameters" << std::endl;
- help(argv1);
- }
-}
-
-int main(int argc, char* argv[])
-{
-// int fd_client;
-// socklen_t len;
-// struct sockaddr_in sock_client;
-
-// len = sizeof (struct sockaddr_in);
- check_args(argc, argv[0], argv[1]);
- Server server(atoi(argv[1]), 3);
- server.get_list_fd();
-// server.start_signal();
-// while (gl_handle != -1)
-// {
-// fd_client = 0;
-// if ((fd_client = accept(server.get_fd(),
-// (struct sockaddr *)&(sock_client), &len)) > 0)
-// gl_handle = gl_handle | 2;
-// std::list<int> list_fd;
-// if (2 == (gl_handle & 2))
-// {
-// server.accept_client(fd_client);
-// server.send_signal(fd_client);
-// }
-// Data<Data_exemple> data;
-// server.wait_signal(list_fd);
-// server.received_data(data, list_fd);
-
-// Data<Data_string> data_string;
-// Data_string ack("Aknowledge");
-// data_string.add_data(ack);
-// server.send_data(data_string, list_fd);
-
-// gl_handle = 0;
-// }
-// return (0);
-}