×

Discussion Board

Results 1 to 10 of 10
  1. #1
    Registered User
    Join Date
    May 2005
    Posts
    6

    how can i come to know bluetooth connection from remote device

    Hi,
    i m developing bluetooth application, in this i need to know, when remote device is trying to connect.
    i created bluetooth socket server. i m waiting for bluetooth connection. when i get connection request from remote device, built in application popping up "blutooth connection request"
    How can i solve this problem??. plz help me to solve this problem.

    Regards,
    Santosh...

  2. #2
    Regular Contributor
    Join Date
    Nov 2004
    Posts
    153
    It should work if you have correctly implemented the functionality.

    Have you made an asynchronous or synchronous request to wait for the connection on the listening port?

    If possible,paste the code here...................

  3. #3
    Registered User
    Join Date
    May 2005
    Posts
    6
    Hi,
    i m using asynchronous request (active object) to wait for connection.

    i m copying my code here.


    CConnect::CConnect():CActive(0)
    {
    iState = 0;
    //close socket
    ListenC.Close();
    iCSok.Close();
    ServC.Close();
    iCoeEnv = CEikonEnv::Static();
    CActiveScheduler::Add(this);
    }

    CConnect::~CConnect()
    {
    Cancel();
    ListenC.Close();
    iCSok.Close();
    // Close down the Bluetooth service
    RBTMan btman; // Session to the Security Manager
    TInt err = btman.Connect();

    // Open subsession to the Security Manager, to unregister services with the security manager.
    RBTSecuritySettings secset;
    err = secset.Open(btman);

    TRequestStatus requestStatus;
    secset.UnregisterService(secSettings, requestStatus);
    User::WaitForRequest(requestStatus);

    // Close the security settings subsession
    secset.Close();
    // Close the security manager session
    btman.Close();
    }

    void CConnect::ControlListen()
    {

    /* CREATE CONTROL SERVER & ACCEPT INCOMING CONNECTION */
    //Connect to the control socket server
    ServC.Close();
    ServC.Connect();

    //// load protocol,
    User::LeaveIfError(ServC.FindProtocol(_L("RFCOMM"), pInfo));

    //Open a listen socket
    ListenC.Open(ServC,pInfo.iAddrFamily,pInfo.iSockType,KRFCOMM);

    TInt channel;
    User::LeaveIfError(ListenC.GetOpt(KRFCOMMGetAvailableServerChannel,KSolBtRFCOMM,channel));

    //setup address
    addr.SetPort(channel);

    //bind
    User::LeaveIfError(ListenC.Bind(addr));

    //Security Manager
    SetSecurityL(channel);

    //listen
    User::LeaveIfError(ListenC.Listen(1));

    //close previous open socket
    iCSok.Close();

    //open blank socket
    User::LeaveIfError(iCSok.Open(ServC));
    //Accept incoming connection
    TRequestStatus status;
    ListenC.Accept(iCSok,iStatus);

    SetActive();
    }

    void CConnect::RunL()
    {
    if(iStatus!=KErrNone)
    {
    return;
    }
    iState++;

    switch(iState)
    {

    case 1: CEikonEnv::Static()->InfoWinL(_L("In RunL "),_L("Connection Request"));
    break;
    default:
    break;
    }

    }

    void CConnect:oCancel()
    {
    //close listening socket
    ListenC.Close();
    iList->iCSok.Close();
    ServC.Close();
    Cancel();
    }

    void CConnect::SetSecurityL(TInt aChannel)
    {
    // setup channel security
    TRequestStatus status;
    RBTMan secManager;
    RBTSecuritySettings secDatabase;

    // connect to security manager
    User::LeaveIfError(secManager.Connect());
    // CleanupClosePushL(secManager);
    User::LeaveIfError(secDatabase.Open(secManager));
    // CleanupClosePushL(secDatabase);

    // setup security
    TUid settingsUID;
    settingsUID.iUid = 0x2345; //// here what i suppose to set.my application uid or what?
    secSettings.SetUid(settingsUID);
    secSettings.SetChannelID(aChannel);
    secSettings.SetProtocolID(KSolBtRFCOMM);
    secSettings.SetAuthentication(ETrue);
    secSettings.SetAuthorisation(EFalse);
    secSettings.SetEncryption(EFalse);

    // register settings with security
    secDatabase.RegisterService(secSettings, status);
    User::WaitForRequest(status);
    if(status!=KErrNone)
    {
    return;
    }
    }
    Thanks...
    Santosh...

  4. #4
    Regular Contributor
    Join Date
    Nov 2004
    Posts
    153
    You have to set your application UID in the SetSecurityL() function.

    Also,did you created the service record in the Local Bluetooth service database?

  5. #5
    Registered User
    Join Date
    May 2005
    Posts
    6
    hi,

    thanks for quick reply.
    i m not created service records in bluetooth database, is there is any example to follow.

    Santosh....

  6. #6
    Regular Contributor
    Join Date
    Nov 2004
    Posts
    153
    Have a look at the \Series60Ex folder in your SDK. There are plenty of examples related to BT in the SDK.


    BR,
    Sunil

  7. #7
    Registered User
    Join Date
    May 2005
    Posts
    6
    hi sunil,
    Good morning...
    i created service record, and i m advertising my services. then also i m not able to get connection to my application. built in application is running.
    what to do?????

    Thanks...................

    Santosh....

  8. #8
    Regular Contributor
    Join Date
    Nov 2004
    Posts
    153
    Have you set your application UID in the SetSecurityL() function?

    However,RunL() should be called when you are waiting for a connection on the socket.

    Have you checked whether it is going into RunL() of your application or just try out using synchronous request.

    BR,
    Sunil

  9. #9
    Registered User
    Join Date
    May 2005
    Posts
    6
    Hi,
    i m setting uid in SetSecurityL().
    i made asynchronous & synchronous request. i m not getting any response.

    Thanks....

    Santosh....

  10. #10
    Registered User
    Join Date
    Jul 2005
    Posts
    37

    Re: how can i come to know bluetooth connection from remote device

    what about filtering phonecell from an incoming

    bluetooth connection?

    I don't know how to catch the remote device's address

    and name, because I don;t use the

    TBTDeviceResponseParamsPckg package, right?

    I use this :
    =========================
    User::LeaveIfError(iSocketServer.Connect());
    TInt result = iListeningSocket.Open(iSocketServer,

    KServerTransportName);
    if (result != KErrNone)
    {
    iSocketServer.Close();
    User::Leave(result);
    }

    // Get a channel to listen on - same as the

    socket's port number
    TInt channel;
    User::LeaveIfError(


    iListeningSocket.GetOpt(KRFCOMMGetAvailableServerChann

    el, KSolBtRFCOMM, channel)
    );

    TBTSockAddr listeningAddress;
    listeningAddress.SetPort(channel);
    iLog.LogL(_L("Get port = "), channel);



    User::LeaveIfError(iListeningSocket.Bind(listeningAddr

    ess));


    User::LeaveIfError(iListeningSocket.Listen(KListeningQ

    ueSize));

    iAcceptedSocket.Close(); // close old

    connection - if any


    User::LeaveIfError(iAcceptedSocket.Open(iSocketServer)

    ); // Open abstract socket

    iState = EConnecting;
    iListeningSocket.Accept(iAcceptedSocket, iStatus);
    SetActive();

    iLog.LogL(_L("Accept next connection"));

    SetSecurityOnChannelL(EFalse, EFalse, ETrue,

    channel);

    iAdvertiser->StartAdvertisingL(channel);
    iAdvertiser->UpdateAvailabilityL(ETrue);

    ================================

    So, the remote device's data should be in

    iAcceptedSocket (RSocket), but I don't know how to get

    the name and address

    Please somebody help me

    Regards,

    Irma

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×