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 window connect()


Sujet :

Réseau C

  1. #1
    Candidat au Club
    Profil pro
    Inscrit en
    Novembre 2009
    Messages
    3
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2009
    Messages : 3
    Points : 4
    Points
    4
    Par défaut socket window connect()
    bonjour voila je voulais crée un logiciel qui envoie un email automatiquement ,j'ai suivi plusieurs tuto mais la problème il me dit :connect():result too large
    j'ai essayer plusieurs méthode mais rien n'y fais cette erreur reste si vous pouviez me donner un coup de main pour terminer mon programme sa serais sympa

    voila le code:
    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
     
    #include <stdio.h>
    #include <stdlib.h>
    #include <winsock2.h>
    static void init(void);
    static void end(void);
     
    char dest[120] = "RCPT To: <erreur410@hotmail.fr>";
    char sender[120] = "MAIL From: <gerar@gmail.com>";
    char data[1024] ="DATA :azerty";
    char *serveur = "74.125.79.109";
     
    int res = 0;
     
    int main()
    {
     
    init();//initialisation du wsa pour windows
    SOCKET sock = socket(AF_INET, SOCK_STREAM, 0);//creation du socket sockstream =tcp AFinet = ipv4
    if(sock == INVALID_SOCKET)
    {
    perror("socket()"); //verification si il ny a pas derreur
    exit(errno);
    }
     
    SOCKADDR_IN sin = { 0 };
     
    sin.sin_addr.S_un.S_addr = inet_addr(serveur);
    sin.sin_port = htons(25);//recuperation du port
    sin.sin_family = AF_INET;//comment l'envoiyer
    if((res = connect(sock,(struct sockaddr *) &sin, sizeof(sin))) != 0)
    {
    perror("connect()");
    exit(errno);
    }
     
     
    send(sock, sender, strlen(sender),0);
    send(sock, dest , strlen(dest),0);
    send(sock, data, strlen(data),0);
    printf("envoie terminer");
     
    end();
    printf("connection fermer");
    return 0;
    }
     
     
     
     
     
     
     
     
     
    static void init(void)
    {
    #ifdef WIN32
    WSADATA wsa;
    int err = WSAStartup(MAKEWORD(2, 2), &wsa);
    if(err < 0)
    {
    puts("Échec du lancement WSA !");
    exit(EXIT_FAILURE);
    }
    #endif
    }
     
    static void end(void)
    {
    #ifdef WIN32
    WSACleanup();
    #endif
    }

  2. #2
    Candidat au Club
    Profil pro
    Inscrit en
    Novembre 2009
    Messages
    3
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2009
    Messages : 3
    Points : 4
    Points
    4
    Par défaut
    bonjour j'ai des nouvelle pour ceux qui suive je n'est plus d'erreur result too long mais il ne passe toujour pas le verification que la connection a eter bien faite voila le resultat de l'exécution
    http://ad1rie1.ifrance.com/erreur.png
    j'aimerais que mon programme fonctionne si vous pouviez m'aidez sa serais sympa
    et le nouveaux code :
    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
     
     
    #include <stdio.h>
    #include <stdlib.h>
    #include <winsock2.h>
    static void init(void);
    static void end(void);
     
    char dest[120] = "EHLO client\r\nMAIL FROM:<erreur410@hotmail.fr>\r\n";
    char sender[120] = "RCPT TO:<gerar@gmail.com>\r\n";
    char sujet[] = "monemail";
    char data[1024] ="voila mon message ^^";
    char serveur[] = "smtp.live.com";
    char test[] = "";
    int main()
    {
     
    init();//initialisation du wsa pour windows
    SOCKET sock = socket(AF_INET, SOCK_STREAM, 0);//creation du socket sockstream =tcp AFinet = ipv4
    SOCKADDR_IN sin = { 0 };
    struct hostent *hostinfo;
    hostinfo = gethostbyname(serveur);
    if(sock == -1)
    {
    perror("socket()"); //verification si il ny a pas derreur
    exit(errno);
    }
     
    printf("Appel de gethost by name %s\n", serveur);
    sin.sin_addr.s_addr  = hostinfo->h_addr;
    sin.sin_port = htons(25);//recuperation du port
    sin.sin_family = AF_INET;//comment l'envoiyer
    printf("configuration ok\n");
    connect(sock,(SOCKADDR *)&sin,sizeof(sin));
     
     
     
    char buffer[1024] = {0};
    char reponce[1024] = {0};
    send(sock,sender,strlen(sender),0);
    recv(sock, reponce, 1023, 0);
    printf("recu:%s\n",reponce);
    send(sock,dest,strlen(dest),0);
    recv(sock, reponce, 1023,0);
    printf("recu:%s\n",reponce);
    sprintf(buffer,"DATA\r\n");
    send(sock,buffer,strlen(buffer),0);
    recv(sock, reponce,1023,0);
    printf("recu:%s\n",reponce);
    sprintf(buffer,"From: %s\r\nTo: %s\r\nSubject: %s\r\n%s\r\n.\r\n\r\n",sender,dest,sujet,data);
    send(sock,buffer,strlen(buffer),0);
    recv(sock, reponce,1023,0);
    printf("recu:%s\n",reponce);
    sprintf(buffer,"QUIT\r\n");
    send(sock,buffer,strlen(buffer),0);
    recv(sock,reponce,1023,0);
    printf("recu:%s\n",reponce);
    perror("envoi()");
     
     
     
    printf("envoie terminer\n");
     
    end();
    printf("connection fermer\n");
    return 0;
    }
     
     
     
     
     
     
     
     
     
    static void init(void)
    {
    #ifdef WIN32
    WSADATA wsa;
    int err = WSAStartup(MAKEWORD(2, 2), &wsa);
    if(err < 0)
    {
    puts("Échec du lancement WSA !");
    exit(EXIT_FAILURE);
    }
    #endif
    }
     
    static void end(void)
    {
    #ifdef WIN32
    WSACleanup();
    #endif
    }

  3. #3
    Candidat au Club
    Profil pro
    Inscrit en
    Novembre 2009
    Messages
    3
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2009
    Messages : 3
    Points : 4
    Points
    4
    Par défaut
    bon en fait g reussi (merci google ) j'ai découvert que les serveur smtp utilisait pas forcement le port 25 et donc mon programme ne se connectai pas au bon port
    je poste sa au cas ou il y en a qui passerais derrière avec la même erreur

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

Discussions similaires

  1. [Reseau] probleme de socket windows
    Par le novice2 dans le forum Réseau
    Réponses: 4
    Dernier message: 24/07/2007, 19h13
  2. Socket windows/Linux
    Par yodaime dans le forum C++
    Réponses: 7
    Dernier message: 11/04/2006, 16h33
  3. [SOCKET] Windows et linux
    Par Gmrinfo dans le forum C++
    Réponses: 3
    Dernier message: 21/02/2006, 22h44
  4. [socket & windows & accept]
    Par Magique dans le forum Réseau
    Réponses: 7
    Dernier message: 30/04/2004, 23h34

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