Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
1137 connectés 

  FORUM HardWare.fr
  Programmation
  C

  Problème Socket Bluetooth

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

Problème Socket Bluetooth

n°1754191
stzup7
Posté le 01-07-2008 à 18:31:35  profilanswer
 

Bonjour à tous,
 
depuis un petit moment j'essaie de faire un programme qui puisse communiquer avec mon téléphone portable.
Je me confronte cependant à un problème au moment de la création d'un socket bluetooth.
 
Je débute en tout ce qui concerne la communication via socket, mais là ça bloque avant :
Le début de la fonction correspond à du code à microsoft, utilisé pour les fonctions WSA*
 
 
int  main(int ac, char **av)
{
 
 int  s; /*mon socket*/
 
/*les trucs à crosoft*/
    WORD wVersionRequested;
    WSADATA wsaData;
    int err;
 
    wVersionRequested = MAKEWORD(2, 2);
    err = WSAStartup(wVersionRequested, &wsaData);
    if (err != 0) {
        printf("WSAStartup failed with error: %d\n", err);
        return 1;
    }
 
    if (LOBYTE(wsaData.wVersion) != 2 || HIBYTE(wsaData.wVersion) != 2) {
        printf("Could not find a useable version of Winsock.dll\n" );
        WSACleanup();
        return 1;
    }
    else
        printf("The Winsock 2.2 dll was found okay\n" );
         
 
/*là c'est moi qui prend le relai*/
 printf("debut\n" );
 s = socket(AF_BTH, SOCK_STREAM, BTHPROTO_RFCOMM);
 if (s == INVALID_SOCKET)
  printf("non %d\n", WSAGetLastError());
 else
  printf("oui\n" );
 
 printf("fin\n" );
 WSACleanup();
 return (0);
}
 
Ce qu'il se passe :
Le programme trouve le socket invalide, et m'écrit, tel que je lui demande, "non" suivi du numéro d'erreur, en l'occurence 10047
 
d'après Microsoft :
http://msdn.microsoft.com/en-us/li [...] S.85).aspx
WSAEAFNOSUPPORT
10047
 
Address family not supported by protocol family.
 
    An address incompatible with the requested protocol was used. All sockets are created with an associated address family (that is, AF_INET for Internet Protocols) and a generic protocol type (that is, SOCK_STREAM). This error is returned if an incorrect protocol is explicitly requested in the socket call, or if an address of the wrong family is used for a socket, for example, in sendto.
 
OR :
http://msdn.microsoft.com/en-us/li [...] S.85).aspx
AF_BTM (il y a un define AF_BTM AF_BTH)
32
 
The Bluetooth address family. This address family is supported on Windows XP SP2 or later if the computer has a Bluetooth adapter and driver installed.
 
Je suis bien sous Windows XP SP2 (je suis passé au SP3 mais ça marche pas non plus, j'ai bien un adaptateur bluetooth (intégré) qui fonctionne avec les logiciels de base)
 
POUR FINIR :
toujours d'après le man socket() de crosoft :
BTHPROTO_RFCOMM
3
 
The Bluetooth Radio Frequency Communications (Bluetooth RFCOMM) protocol. This is a possible value when the af parameter is AF_BTH and the type parameter is SOCK_STREAM. This protocol is supported on Windows XP SP2 or later.
 
Les paramètres que je donne à ma fonction socket sont bien AF_BTH, SOCK_STREAM et BTHPROTO_RFCOMM
Malgré cela WSAGetLastError me dis que l'address family n'est pas supporté, je ne comprends pas pourquoi.
 
les includes que j'ai sont, dans l'ordre,  
#include <stdlib.h>
#include <stdio.h>
#include <Winsock2.h>
#include <Ws2bth.h>
#include <Bthsdpdef.h>
#include <BluetoothAPIs.h>
 
Si vous pouviez m'aider en me disant d'où ça vient, je vous en serai reconnaissant.
Vous devriez pouvoir facilement compiler ce code sous windows.
 
Merci, n'hésitez pas à poser des questions.

mood
Publicité
Posté le 01-07-2008 à 18:31:35  profilanswer
 

n°1860571
surfzoid
Posté le 11-03-2009 à 23:35:43  profilanswer
 

Quand tu dit tout les logiciel, ton dongle blutooth utilise bien le driver generic de crosoft, tu as le petit icone bt dans la barre des taches et ton téléphone est ds la list de ses perif ?


Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation
  C

  Problème Socket Bluetooth

 

Sujets relatifs
problème SDCC et CONTEXTProbleme URL Re-writing
Probleme de ressources (rc) sous VC++ (icones++)probleme redimensionnement image dans un tableau
Problème avec Servlet[résolu]Problème Carateres japonais UTF8 et IE7 php
Problème redirection 301 htaccess[ORACLE] Problème de création de clé étrangère
MS-DOS : Boucle For, IF et Find imbriqués, probleme d'affectation[Resolu] Problème portabilité entre PC sous WinXP
Plus de sujets relatifs à : Problème Socket Bluetooth


Copyright © 1997-2022 Hardware.fr SARL (Signaler un contenu illicite / Données personnelles) / Groupe LDLC / Shop HFR