.NET Components for Mobility

Problem in bluetoothClient.connect()

Last post 01-09-2010 9:09 AM by jihmantiquilla. 3 replies.
Page 1 of 1 (4 items)
Sort Posts: Previous Next
  • 12-29-2009 3:19 AM

    • ahmad
    • Not Ranked
    • Joined on 11-09-2009
    • Posts 2

    Problem in bluetoothClient.connect()

    Dear ,

    I am using 32Feet.NET version 2.3 and every time I connect to a Bluetooth device from a Windows Mobile 6 Device via serial port , the first time it works fine and I can send data  but if disconnect and then try to connect a second , time nothing happens the request just hangs . I would really appreciate if you could shed some light on this issue.

    here is  the code I wrote

    //Connect function
    public int ConnectToBluetoothDevice(InTheHand.Net.BluetoothAddress DeviceAddress, Guid Service)
           {
             
               try
               {
                  
                       bluetoothClient = new BluetoothClient();
                       InTheHand.Net.BluetoothEndPoint EndPoint = new InTheHand.Net.BluetoothEndPoint(DeviceAddress, Service);
                       bluetoothClient.Connect(EndPoint);
                  
               }
                catch (ObjectDisposedException ode)
               {
                   return ClientClosed;
               }

               catch (System.Net.Sockets.SocketException socketException)
               {
                   return ConnectSocketException;
               }

               return ConnectToClientSuccess;
           }

    public int SendTextToDevice(string TextToSend)

    {

    if (String.Equals(TextToSend, null))

    return SendTextErrorInvalidInputs;

    try

    {

    if (bluetoothClient.Connected)

    {

    straem = bluetoothClient.GetStream();

    steramWriter =
    new StreamWriter(straem);

    steramWriter.Write(TextToSend);

    steramWriter.Flush();

    }

    else

    {

    return SendTextErrorClientNotConnected;

    }

    }

    catch (System.IO.IOException ioException)

    {

    return SendTextErrorSndingError;

    }

    return 0;

    }

    // Disconnect function
    public int DisConnectFromBluetoothDevice()
           {
               if (BluetoothClient.Equals(bluetoothClient, null))
               {
                   return BluetoothClientNull;

               }
               else
               {
                   straem.Close();
                   bluetoothClient.Close();
                  
               }
               return DisconnectSuccess;
           }

    Filed under: ,
  • 12-30-2009 1:01 PM In reply to

    Re: Problem in bluetoothClient.connect()

    As long as the first connection is closed then a new connection should work fine.  And if it wasn't then the second connect attempt would simply fail after a period (Bluetooth only allows one connection to a server from each client device).  If you're seeing a longer/different hang then it seems more likely that there's something wrong with the remote device.  Perhaps it needs sometime to recover after the first connection.  Can you try connecting to it from a PC, or tests you application on the WM device after a fake server on the PC created with BluetoothListener to troubleshoot whether the problem is at the WM or server-device end.

  • 01-02-2010 1:32 AM In reply to

    • ahmad
    • Not Ranked
    • Joined on 11-09-2009
    • Posts 2

    Re: Problem in bluetoothClient.connect()

    thank you for the response.

    what i did is the following

    1- at the begining of the connect function i disabled the bluetooth device

    2- waited for 5 seconds

    3- enabled the bluetooth device

    4- try to connect

    also after the connection is made and the data is sent i did the following

     1- waited for 5 seconds

     

    this seems to solve the problem but i still do not know if the problem is form the Pocket PC Device hardwar/ software (Microsoft Bluetooth stack) or it is from the recevier ??

    regards,

    Filed under: ,
  • 01-09-2010 9:09 AM In reply to

    Re: Problem in bluetoothClient.connect()

    try to add .Dispose upon Closing the Connection...
Page 1 of 1 (4 items)
Copyright © 2001-2012 In The Hand Ltd. All rights reserved. Terms of Use and Privacy Policy. OrcsWeb's Windows Cloud Server Hosting