En quoi ai je fais une erreur ? j'ai juste décidé d'utiliser la version 1 au lieu de la 2...
Version imprimable
En quoi ai je fais une erreur ? j'ai juste décidé d'utiliser la version 1 au lieu de la 2...
Et tu as changé la bibliothèque ? Comme tu ne testes pas le retour de WSAStartup(), tu ne sais pas ce qui se passe...Citation:
Envoyé par xyz
Et je passe sur PF_INET... Il y a des choses qui on du mal à rentrer on dirait...Citation:
Envoyé par -ed-
De plus, quel intérêt ? Elle est obsolète et beaucoup moins portable que la version 2.
Oui j'avais changé la bibliothèque, mais je remets la version 2 si est plus complète.
Oui, et elle a de meilleures chances de fonctionner avec ton système... La version 1 ça date de Windows 3.11... Les années 90... T'étais né ?Citation:
Envoyé par xyz
Pourquoi cette ligne
En TCP/IP, cette ligne fonctionne très bien.Code:
1
2 sock.sin_addr.S_un.S_addr = inet_addr(adresse); // Utiliser pour TCP/IP
Code:
1
2 sock.sin_addr.s_addr = inet_addr(adresse); // Utiliser pour TCP/IP
Ouais depuis bien longtemps..Citation:
Envoyé par Emmanuel Delahaye
Ah j'ai aussi testé le retour de WSAStartup() qui me renvoie 0.
Bon j'ai résolu mon problème je pose le source pour ceux que ca interesse. Merci à ceux qui m'ont aidé.
Code:
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 #include "port_serie.h" #pragma comment(lib, "wsock32.lib") int sock(char *buffer) { WSADATA wsaData; SOCKET descripteur; int res; struct sockaddr_in sock; char *adresse = "172.16.19.125"; res = WSAStartup(MAKEWORD(1,0), &wsaData); if (res !=0) { puts("error"); } descripteur = socket(AF_INET, SOCK_STREAM,IPPROTO_TCP); // Utiliser pour TCP/IP if (descripteur != SOCKET_ERROR) { sock.sin_family = AF_INET; sock.sin_port = htons(1024); sock.sin_addr.s_addr = inet_addr(adresse); } if(connect(descripteur, (struct sockaddr*) (&sock), sizeof(sock)) == SOCKET_ERROR) errors(); if((send(descripteur, buffer, strlen(buffer), 0)) == SOCKET_ERROR) // errors(); getch(); closesocket(descripteur); WSACleanup(); return '\0'; }
En cas d'erreur, tu informes et tu continues ? T'as peur de rien !Citation:
Envoyé par xyz
On pourrait avoir la version qui compile, ou c'est secret...
Code:
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 Compiling: main.c main.c:2:24: port_serie.h: No such file or directory main.c:4: warning: ignoring #pragma comment main.c:9: warning: no previous prototype for 'sock' main.c: In function `sock': main.c:11: error: `WSADATA' undeclared (first use in this function) main.c:11: error: (Each undeclared identifier is reported only once main.c:11: error: for each function it appears in.) main.c:11: error: syntax error before "wsaData" main.c:12: error: `SOCKET' undeclared (first use in this function) main.c:14: warning: declaration of 'sock' shadows a global declaration main.c:9: warning: shadowed declaration is here main.c:14: error: storage size of 'sock' isn't known main.c:15: warning: initialization discards qualifiers from pointer target type main.c:17: error: implicit declaration of function `WSAStartup' main.c:17: warning: nested extern declaration of `WSAStartup' main.c:17: error: implicit declaration of function `MAKEWORD' main.c:17: warning: nested extern declaration of `MAKEWORD' main.c:17: error: `wsaData' undeclared (first use in this function) main.c:21: error: implicit declaration of function `puts' main.c:21: warning: nested extern declaration of `puts' <internal>:0: warning: redundant redeclaration of 'puts' main.c:26: error: `descripteur' undeclared (first use in this function) main.c:26: error: implicit declaration of function `socket' main.c:26: warning: nested extern declaration of `socket' main.c:26: error: `AF_INET' undeclared (first use in this function) main.c:26: error: `SOCK_STREAM' undeclared (first use in this function) main.c:26: error: `IPPROTO_TCP' undeclared (first use in this function) main.c:27: error: `SOCKET_ERROR' undeclared (first use in this function) main.c:31: error: implicit declaration of function `htons' main.c:31: warning: nested extern declaration of `htons' main.c:32: error: implicit declaration of function `inet_addr' main.c:32: warning: nested extern declaration of `inet_addr' main.c:37: error: implicit declaration of function `connect' main.c:37: warning: nested extern declaration of `connect' main.c:38: error: implicit declaration of function `errors' main.c:38: warning: nested extern declaration of `errors' main.c:40: error: implicit declaration of function `send' main.c:40: warning: nested extern declaration of `send' main.c:40: error: implicit declaration of function `strlen' main.c:40: warning: nested extern declaration of `strlen' <internal>:0: warning: redundant redeclaration of 'strlen' main.c:44: error: implicit declaration of function `getch' main.c:44: warning: nested extern declaration of `getch' main.c:45: error: implicit declaration of function `closesocket' main.c:45: warning: nested extern declaration of `closesocket' main.c:46: error: implicit declaration of function `WSACleanup' main.c:46: warning: nested extern declaration of `WSACleanup' main.c:14: warning: unused variable `sock' Process terminated with status 1 (0 minutes, 1 seconds) 26 errors, 21 warnings