Bonjour,
Je débute ne C++ et je dois déjà réaliser un jeu de cours en réseau.
Je suis chargé de la parti réseau.
Je dois donc codé un server pouvant gérer plusieur client; pour cela j'utilise la fonction select.
Le probléme est que cette fonction me renvoi toujrou -1.
Voici la pati de mon code utilisant le select
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
 
int	Connection::boucle(void)
{
  struct timeval	tv;
  SOCKET			cs;
  SOCKET			fd_max;
  t_client			*begin_cl;
  fd_set			readf;
  int				rt_select;
 
  tv.tv_sec = 1;
  tv.tv_usec = 0;
  begin_cl = NULL;
  while (1)
    {
      fd_max = ini_fd_set(&readf, begin_cl);
	  //  , &readf
      rt_select = select  (s + (unsigned int) 1, NULL, NULL, NULL, NULL);
		 if (rt_select < 0)
		{
			printf("errno %d\n", errno);
			perror(PROJ_NAME);
			printf("close\n");
			fd_max = ini_fd_set(&readf, begin_cl);
		}
      else if (FD_ISSET(s, &readf))
	{
	  cs = accept(s, (SOCKADDR *)&client_sin, &client_sin_len);
	  printf("accept\n");
	  begin_cl = Client_ser::ajoute_liste(cs, begin_cl);
	}
      begin_cl = parse_fd_set(&readf, begin_cl);
    }
}
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
 
SOCKET	Connection::ini_fd_set(fd_set *readf, t_client *cl)
{
  SOCKET	fd_max;
  t_client	*crt;
 
  fd_max = 0;
  FD_ZERO(readf);
  FD_SET(1, readf);
  FD_SET(s, readf);
  if ( s > fd_max)
    fd_max = s;
  crt = cl;
  while (crt)
    {
      FD_SET(crt->fd, readf);
      if (crt->fd > fd_max)
 	fd_max = crt->fd;
      crt = crt->next;
    }
  return (fd_max);
}
A oui j'avait oublier un petit truc je développe sous Visual Studio.