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

  FORUM HardWare.fr
  Programmation

  [C] Creer un serveur ftp

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

[C] Creer un serveur ftp

n°19358
Titoine42
Posté le 19-03-2001 à 19:02:35  profilanswer
 

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:

mood
Publicité
Posté le 19-03-2001 à 19:02:35  profilanswer
 

n°19370
verdoux
And I'm still waiting
Posté le 19-03-2001 à 19:31:35  profilanswer
 

Il faut utiliser la fonction "accept" qui crée une nouvelle socket quand une connexion a lieu.

n°19372
Titoine42
Posté le 19-03-2001 à 19:32:56  profilanswer
 

Comment est-ce que je sais qu'une nouvelle connection a lieu?

n°19373
verdoux
And I'm still waiting
Posté le 19-03-2001 à 19:38:08  profilanswer
 

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.


Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation

  [C] Creer un serveur ftp

 

Sujets relatifs
[PHP] Créer des gifs animés?[JAVA] Créer un exe...
php, authentification au serveur[HTML et PHP] créer une variable parametre
Comment je fais pour me connecter a serveur news...[Access et VB] Je veux creer un replica partiel d'une base, help !!!
[Acces]: Comment creer une vue?serveur apache + php POUR WINDOZE?
Routines VB6 pour gerer un serveur Half-Life[C] creer une fonction strdel
Plus de sujets relatifs à : [C] Creer un serveur ftp


Copyright © 1997-2022 Hardware.fr SARL (Signaler un contenu illicite / Données personnelles) / Groupe LDLC / Shop HFR