IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Réseau C Discussion :

socket: Address family not supported by protocol ??


Sujet :

Réseau C

  1. #1
    Membre du Club
    Profil pro
    Inscrit en
    Avril 2004
    Messages
    189
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2004
    Messages : 189
    Points : 60
    Points
    60
    Par défaut socket: Address family not supported by protocol ??
    Voila tout est dans le titre... Lors d'un connect() à un serveur en tcp, je recois cette erreur: Address family not supported by protocol..

    les 2 socket sont créées en TCP et bindé comme il faut...

    Voici les sources..


    SEVEUR:

    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
    35
    36
    void graine()
    {
    	char nomFichier[50] ;	
     
    	int fd ;
    	int lg = sizeof(struct sockaddr_in) ;
    	struct sockaddr_in client;
     
    	printf("Taper le nom du fichier à partager\n") ;
    	scanf("%s", nomFichier) ;
     
    	decoupe(nomFichier) ;
     
     
    	execlp("./tracker", "./tracker", nomFichier, NULL);
     
    	int s_ecoute = createBindInetSocketTCP(SOCK_STREAM,1234) ;
     
    	if (listen(s_ecoute,10)<0)
    	{
    		perror("erreur listen") ;
    		exit(-2) ;
     
    	}
    	else
     
    	if ((fd=accept(s_ecoute, (struct sockaddr *)&client,&lg))==-1)
    	{
    		perror("erreur accept") ;
    		exit(-1) ;
     
    	}	
     
     
     
    }
    CLIENT:
    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
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    void pair()
    {
    	int s = createBindInetSocket(SOCK_DGRAM, 1236) ;
    	int sTCP = createBindInetSocketTCP(SOCK_STREAM,1236) ;
    	char c ;
    	struct sockaddr_in tracker ;
    	struct hostent * host ;
    	char nombreBloc[10] ;
    	int lg=sizeof(struct sockaddr_in)  ;
    	int nbBloc ;
    	int k ;
    	struct sockaddr_in * reponse = malloc(sizeof(struct sockaddr_in)) ; 
     
    	host = gethostbyname("localhost") ; //adresse du serveur qui est en localhost ici
     
    	tracker.sin_family = AF_INET ;
    	tracker.sin_port = htons(1238) ;
     
    	memcpy(&tracker.sin_addr, host->h_addr, sizeof(tracker.sin_addr)) ;
     
    	if (sendto(s,"info?",strlen("info?"),0, (struct sockaddr *)&tracker, sizeof(tracker))<0)
    	{
    		perror("sendto info?");
    		exit(-2) ;
     
    	}
     
     
     
     
     
    	if(recvfrom(s,nombreBloc,10, 0, (struct sockaddr *) &tracker, &lg)<0)
    	{
    		perror("Erreur lors de la reception du nombre de blocs\n") ;
    	}
     
    	sscanf(nombreBloc, "%d", &nbBloc) ;
     
     
     
    	int tab[nbBloc] ;
     
    	for(k=0 ; k<nbBloc;k++) // on initialise le tableau : 1 quand le client a le bloc 0 sinon
    	{
    		tab[k]=0 ;
    	}
    	while(1)
    	{	
    		int continu=1 ;
     
    		for (k=0 ; k<nbBloc && continu ; k++) //recherche du numéro de bloc à télécharger.
    		{
    			if (tab[k]==0)
    			{	
    				continu = 0 ;
    				char bloc[10] ;
     
    				sprintf(bloc, "%d", k) ;
     
    				if (sendto(s,bloc,strlen(bloc),0, (struct sockaddr *)&tracker, sizeof(tracker))<0)
    				{
    					perror("sendto bloc?");
    					exit(-2) ;
    				}
     
     
     
     
    				printf("%s\n", inet_ntoa(reponse->sin_addr.s_addr)) ;	
    				if(recvfrom(s,reponse,sizeof(struct sockaddr_in), 0, (struct sockaddr *) &tracker, &lg)<0)
    				{
    					perror("Erreur lors de la reception de la réponse") ;
    					exit(-1) ;
    				}	
     
    				printf("%s\n", inet_ntoa(reponse->sin_addr.s_addr)) ;	
     
    			}
     
     
    		}
     
    	//on passe en tcp pour le téléchargement du bloc.
     
    		if (connect(sTCP, (struct sockaddr*)&reponse, sizeof (struct sockaddr_in))<0)
    		{
    			perror("erreur connect") ;
    			exit(-1) ;
    		}	
    		else
    		{
    			printf("connect réussi");
     
     
    		}
     
     
    	}	
     
     
     
     
    }

  2. #2
    Expert éminent sénior

    Avatar de fearyourself
    Homme Profil pro
    Ingénieur Informaticien Senior
    Inscrit en
    Décembre 2005
    Messages
    5 121
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : Etats-Unis

    Informations professionnelles :
    Activité : Ingénieur Informaticien Senior
    Secteur : Industrie

    Informations forums :
    Inscription : Décembre 2005
    Messages : 5 121
    Points : 11 877
    Points
    11 877
    Par défaut
    Il y a au moins deux bizarreries dans ton code:

    Mettre du code après:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
       execlp("./tracker", "./tracker", nomFichier, NULL);
    est une erreur puisque exec écrase la portion TEXT du processus et donc le programme initial est perdu, ie: le programme ne reviendra jamais après un exec...

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    connect(sTCP, (struct sockaddr*)&reponse, sizeof (struct sockaddr_in))
    Non seulement, les types de la fonction ne sont pas respecté (ton 2ème argument est un struct sockaddr ** et toi tu le fais passer pour un struct sockaddr* ) mais de plus la fonction connect regarde ce 2eme argument pour y trouver les informations du serveur...

    Jc

  3. #3
    Nouveau membre du Club
    Profil pro
    Étudiant
    Inscrit en
    Octobre 2005
    Messages
    29
    Détails du profil
    Informations personnelles :
    Âge : 42
    Localisation : France, Bas Rhin (Alsace)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Octobre 2005
    Messages : 29
    Points : 33
    Points
    33
    Par défaut
    c'est exactement ce qu j'allai te dire innosang...
    dans ton 2° argument, il faut virer de ton cast le * ....

    Et comme l'a dis si bien fearyourself, ton exec va virer le programme en cours....
    mais le je ne sais pas comment t'aider !

  4. #4
    Membre du Club
    Profil pro
    Inscrit en
    Avril 2004
    Messages
    189
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2004
    Messages : 189
    Points : 60
    Points
    60
    Par défaut
    en gros il faut lancer le tracker en arrière plan c'est ça ?

  5. #5
    Expert éminent sénior

    Avatar de fearyourself
    Homme Profil pro
    Ingénieur Informaticien Senior
    Inscrit en
    Décembre 2005
    Messages
    5 121
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : Etats-Unis

    Informations professionnelles :
    Activité : Ingénieur Informaticien Senior
    Secteur : Industrie

    Informations forums :
    Inscription : Décembre 2005
    Messages : 5 121
    Points : 11 877
    Points
    11 877
    Par défaut
    Si tu veux que ton programme tracker fonctionne en même temps que le reste du code du serveur, alors il faut faire une version multi-thread ou alors un fork/exec...

    Jc

  6. #6
    Membre du Club
    Profil pro
    Inscrit en
    Avril 2004
    Messages
    189
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2004
    Messages : 189
    Points : 60
    Points
    60
    Par défaut
    merci

    en fin de compte, j'ai mis un fork() en regardant bien le numéro du pid pour lancer le second programme

    merci pour ton aide :p

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Erreur Bind: Address family not supported by protocol
    Par sambia39 dans le forum Réseau
    Réponses: 4
    Dernier message: 30/06/2014, 22h50
  2. Réponses: 0
    Dernier message: 06/10/2011, 21h41
  3. Réponses: 0
    Dernier message: 25/04/2010, 02h27
  4. Réponses: 4
    Dernier message: 14/04/2010, 11h38
  5. Réponses: 2
    Dernier message: 25/01/2007, 22h19

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo