Bonjour, j'ai un probleme avec mon programme de socket:
le texte "avant fonction bind...[OK]" S'affiche mais le texte "fonction bind...[OK] ne s'affiche pas. j'en conclue donc que la fonction binf renvoie -1 car si je met
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 #include <iostream> #define LINUX using namespace std; #ifdef LINUX #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> #include <unistd.h> #include <stdio.h> #include <stdlib.h> #define INVALID_SOCKET -1 #define SOCKET_ERROR -1 #define closesocket(param) close(param) typedef int SOCKET; typedef struct sockaddr_in SOCKADDR_IN; typedef struct sockaddr SOCKADDR; int main(int argc, char *argv[]) { SOCKET serveur; SOCKET client; SOCKADDR_IN sin; SOCKADDR_IN sinc; int val=1; cout << "linux" << endl; serveur=socket (AF_INET, SOCK_STREAM, 0); if(serveur != -1) { cout<<"fonction socket.......................................[OK]"<<endl; sin.sin_addr.s_addr = htonl (INADDR_ANY); sin.sin_family = AF_INET; sin.sin_port = htons (23); cout<<"avant fonction bind............................[OK]"<<endl; if(bind(serveur,(SOCKADDR *)&sin, sizeof(sin)) != -1) { cout<<"fonction bind............................[OK]"<<endl; if (listen(serveur,1) != SOCKET_ERROR) { cout<<"fonction listen.......................[OK]"<<endl<<"attente d'une connexion"<<endl; bool val=true; while(val) { cout<<"message apres la boucle"<<endl; socklen_t taille = sizeof(sinc); client=accept(serveur,(SOCKADDR *)&sinc,&taille); if(client != SOCKET_ERROR) { cout<<"connexion etablie"<<endl; val=false; } } } } } closesocket(serveur); closesocket(client); return EXIT_SUCCESS; } #endif #ifdef WINDOWS int main(int argc, char *argv[]) { cout << "windows" << endl; return EXIT_SUCCESS; } #endif, le texte "fonction bind...[OK]" fonctionne.
Code : Sélectionner tout - Visualiser dans une fenêtre à part if(bind(serveur,(SOCKADDR *)&sin, sizeof(sin)) == -1)
Mais je ne voit pas où est l'erreur.
Pouvez vous m'aidez à resoudre ce probleme?
merci d'avance
Partager