Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
4114 connectés 

 


Dernière réponse
Sujet : [C] Creer un serveur ftp
verdoux extrait de "man accept": If no pending connections are present on  the  queue,  and
       the  socket  is  not marked as non-blocking, accept blocks
       the caller until a connection is present.  If  the  socket
       is marked non-blocking and no pending connections are pre-
       sent on the queue, accept returns EAGAIN.
 
       In order to be  notified  of  incoming  connections  on  a
       socket,  you  can  use  select(2)  or poll(2).  A readable
       event will be delivered when a new connection is attempted
       and you may then call accept to get a socket for that con-
       nection.  Alternatively, you can set the socket to deliver
       SIGIO  when activity occurs on a socket; see socket(7) for
       details.

Votre réponse
Nom d'utilisateur    Pour poster, vous devez être inscrit sur ce forum .... si ce n'est pas le cas, cliquez ici !
Le ton de votre message                        
                       
Votre réponse


[b][i][u][strike][spoiler][fixed][cpp][url][email][img][*]   
 
   [quote]
 

Options

 
Vous avez perdu votre mot de passe ?


Vue Rapide de la discussion
verdoux extrait de "man accept": If no pending connections are present on  the  queue,  and
       the  socket  is  not marked as non-blocking, accept blocks
       the caller until a connection is present.  If  the  socket
       is marked non-blocking and no pending connections are pre-
       sent on the queue, accept returns EAGAIN.
 
       In order to be  notified  of  incoming  connections  on  a
       socket,  you  can  use  select(2)  or poll(2).  A readable
       event will be delivered when a new connection is attempted
       and you may then call accept to get a socket for that con-
       nection.  Alternatively, you can set the socket to deliver
       SIGIO  when activity occurs on a socket; see socket(7) for
       details.
Titoine42 Comment est-ce que je sais qu'une nouvelle connection a lieu?
verdoux Il faut utiliser la fonction "accept" qui crée une nouvelle socket quand une connexion a lieu.
Titoine42 Une fois que j'ecoute sur le port passer en parametre, comment est-ce que je sais qu'un client veut se connecter?
 
voici ou j'en suis :
 
void   start_server(int port)
{
  struct sockaddr_in    sin;
  int   sin_len;
 
  if ((gbl->listen_fd = socket(AF_INET, SOCK_STREAM, 0)) == -1)
    fprintf(stderr, "Error creating socket.\n" );
  sin.sin_family = AF_INET;
  sin.sin_port = htons(port);
  sin.sin_addr.s_addr = INADDR_ANY;
  if (bind(gbl->listen_fd, (struct sockaddr *)&sin, sizeof (sin)) == -1)
    fprintf(stdout, "Error binding socket.\n" );
  listen(gbl->listen_fd, 5);
  sin_len = sizeof (sin);
  getsockname(gbl->listen_fd, (struct sockaddr *)&sin, (socklen_t *) &sin_len);
  fprintf(stdout, "Listening on port %d (requested port was %d).\n", ntohs(sin.sin_port), port);
}
 
Merci d'avance :jap:

Copyright © 1997-2025 Groupe LDLC (Signaler un contenu illicite / Données personnelles)