Probleme de compilation socket
Bonjour
Voila je fais des essais sur les sockets c++ mais pour l'instant j'ai pas réussi a compiler j'ai ces erreurs.
Citation:
1>c:\projet\client\client\client.cpp(21): error C3861: 'htons'*: identificateur introuvable
1>c:\projet\client\client\client.cpp(24): error C3861: 'bind'*: identificateur introuvable
1>c:\projet\client\client\client.cpp(25): error C3861: 'listen'*: identificateur introuvable
1>c:\projet\client\client\client.cpp(29): error C2440: '='*: impossible de convertir de 'SOCKET (__stdcall *)(SOCKET,sockaddr *,int *)' en 'SOCKET'
1>c:\projet\client\client\client.cpp(29): error C2440: '='*: impossible de convertir de 'SOCKET (__stdcall *)(SOCKET,sockaddr *,int *)' en 'SOCKET'
1> Aucun contexte dans lequel cette conversion est possible
1>c:\projet\client\client\client.cpp(29): error C3861: 'accept'*: identificateur introuvable
1>c:\projet\client\client\client.cpp(37): error C3861: 'send'*: identificateur introuvable
1>c:\projet\client\client\client.cpp(50): error C3861: 'closesocket'*: identificateur introuvable
1>c:\projet\client\client\client.cpp(52): error C3861: 'WSACleanup'*: identificateur introuvable
1>
1>ÉCHEC de la build.
1>
1>Temps écoulé 00:00:05.85
Je pensais que c'etai ma bibliothèque qui étais pas linker mais apparemment
cette ligne le fais
Code:
#pragma comment(lib, "ws2_32.lib")
client.h
Code:
1 2 3 4 5 6 7 8 9
|
#include <windows.h>
#include <winsock2.h>
#include <iostream>
#pragma comment(lib, "ws2_32.lib")
#define port 5169
using namespace std;
SOCKET sock;
SOCKET csock; |
client.cpp
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
|
#include "Client.h"
int main()
{
//initialisation de la variable WSADATA
WSADATA WSAData;
SOCKADDR_IN sin;
SOCKADDR_IN csin;
char buffer[50];
do
{
if (WSAStartup(MAKEWORD(2,0), &WSAData)!=0)
cout << "CLIENT: Impossible d'initialiser Winsock";
else
{
sock = socket(AF_INET, SOCK_STREAM, 0);
sin.sin_addr.s_addr = htonl(INADDR_ANY); //adresse du server
sin.sin_family = AF_INET;
sin.sin_port = htons(port);
bind(sock, (SOCKADDR *)&sin, sizeof(sin));
listen(sock, 8);
int sinsize = sizeof(csin);
if((csock = accept(sock, (SOCKADDR *)&csin, &sinsize)) != INVALID_SOCKET) //si le serveur est connecter
{
cout << "CLIENT: connexion reussi \n";
}
else
{
cout << "CLIENT: connexion echouer\n";
}
closesocket(sock);
//closesocket(csock);
WSACleanup();
}
}
while(1);
return 0;
} |