×

Discussion Board

Results 1 to 4 of 4
  1. #1
    Registered User
    Join Date
    Jul 2006
    Posts
    7

    6630 Hangs up on Service Search :(

    Hi to you all;
    I'm trying to make a Bluetooth connection between a mobile Phone and a PC in order to get my phone send text messages to the PC and I'm facing several problems, for which I call for your help and attention.

    Problems: My Nokia 6630 hangs up in the first wait, I've replaced the wait() by a Boolean but the problem persists, when I launch the Service Search. The Siemens S65 doesn't, but freezes when it tries to get the service name. Does anyone know an easy way to get the service name?

    My Nokia's firmware version is: 5.03.08(17-08-05 RM-1).

    Below are two sources, my Server and my Client, and any help correcting any mistakes you may find will be very much appreciated.



    First the server class, adapted from the jsr82 example, a very simple service registration:
    Code:
    public class DiABluBTServiceRegistration0 {
        
        public DiABluBTServiceRegistration0() {
        }
        
        public static void main(String[] args) {
            
            StreamConnectionNotifier server = null;
            ServiceRecord record;
            LocalDevice local;
            String message = "";
            byte[] data = new byte[20];
            int length;
    
            try {
                local = LocalDevice.getLocalDevice();
                local.setDiscoverable(DiscoveryAgent.GIAC);
            } catch (BluetoothStateException e) {
                System.err.println("Failed to start service");
                System.err.println("BluetoothStateException: " + e.getMessage());
                return;
            }
    
            try {
                server = (StreamConnectionNotifier)Connector.open("btspp://localhost:F0E0D0C0B0A000908070605040302013;name=666Service");    
                
            } catch (IOException e) {
                System.err.println ("Failed to start service");
                System.err.println("IOException: " + e.getMessage());
                return;
            }
    
    
              while (!(message.equals("Stop Server"))) {
    
                message = "";
                StreamConnection conn = null;
    
                try {
                    try {
                        System.out.println("Service registered.Waiting connections...");
                        conn = server.acceptAndOpen();
                        System.out.println("Client connected!!");
                    } catch (IOException e) {
                          e.printStackTrace();
                        return;
                    }
    
                    InputStream in = conn.openInputStream();
    
                    length = in.read(data);
                    while (length != -1) {
                        message += new String(data, 0, length);
                    System.out.println("Message = " + message);
    
    
                        try {
                            length = in.read(data);
                        } catch (IOException e) {
       
                            e.printStackTrace ();
                            break;
                        }
                   
                    }
    
                    in.close();
    
                } catch (IOException e) {
                      e.printStackTrace();
                } finally {
                    if (conn != null) {
                        try {
                            conn.close();
                        } catch (IOException e) {
        
                            e.printStackTrace();
                        }
                    }
                }
            }
    
            try {
                server.close ();
            } catch (IOException e) {
    
                e.printStackTrace();
    
            }
    }
    
    }
    ------------------------------------------------------------------------------------------------------------
    The client class responsible for the discovery is below:
    Code:
    public class dbBTdiscovery2  implements DiscoveryListener {
    
        private DiscoveryAgent discoveryAgent;
        private LocalDevice localDevice;
        private ServiceRecord record;
        private Vector deviceList;
        private Vector serviceList;
        public boolean DISCOVERY_COMPLETED = false;
        public boolean SEARCH_COMPLETED = false;
        
        /* This class GUI */
        private DiABluTester parent;
        
        /* Creates a new instance of dbBTdiscovery2 */
        public dbBTdiscovery2(DiABluTester dbT) {
            
            parent = dbT;
            record = null;
            deviceList = new java.util.Vector();
            serviceList = new java.util.Vector();
    
            try {
                    localDevice = LocalDevice.getLocalDevice();
            } catch (BluetoothStateException btE) {
                log(btE.getMessage());
                btE.printStackTrace();
            }
            
            discoveryAgent = localDevice.getDiscoveryAgent();    
            
        }
        
        public DiABluService findDiABlus(){
            
            // Create our return list
           Vector DiABluServiceList = new java.util.Vector();
           
    
            DISCOVERY_COMPLETED = false;
            
            DiABluService dbS = null;
                            
            try {
        
                discoveryAgent.startInquiry(DiscoveryAgent.GIAC, this);
            
            } catch (BluetoothStateException e) {
                
                log("ERROR!:"+e.getMessage());
                e.printStackTrace();
            
            }
    
           log("Waiting");
            while (!DISCOVERY_COMPLETED){}        
           log("Done waiting.Processing results...");
           
            if (serviceList!=null && serviceList.size ()!=0){
                for (int i=0;i<serviceList.size();i++){
                    
                    int srTL = ((ServiceRecord[])serviceList.elementAt(i)).length;
                    ServiceRecord[] srT = new ServiceRecord[srTL];
                    srT = ((ServiceRecord[])serviceList.elementAt(i));
                    log("Getting url");
                    String conn = srT[0].getConnectionURL(ServiceRecord.NOAUTHENTICATE_NOENCRYPT, false);
                    log(conn);
                    
                    /* Blocks on Nokia & Siemens                     
                     DataElement de = srT[0].getAttributeValue(0x100);
                     String sName = (String)de.getValue();
                    */    
                  String sName = "DiAbluService "+i;                                dbS = new        DiABluService(conn,sName);
                    log("New DiABluService("+conn+","+sName+")");
                    DiABluServiceList.addElement(dbS);
                }
           }else
           {
               log("ERROR:serviceList is empty");
           }
           
           
            
           return DiABluServiceList;
        }
        
         public void deviceDiscovered(RemoteDevice btDevice, DeviceClass cod) {
            if (cod.getMajorDeviceClass()==256) {
    
                deviceList.addElement(btDevice);
            }       
        }
         
         public void inquiryCompleted(int discType){
            
            log("INQUIRY100%:"+discType);
            
            
            if (deviceList!=null && deviceList.size()>0){          
                RemoteDevice[] devList = new RemoteDevice[deviceList.size()];
                deviceList.copyInto(devList);
                searchServices(devList);     
            }else {  
                DISCOVERY_COMPLETED = true;
            }      
        }
        
        private void searchServices(RemoteDevice[] devList) {
         
         log("ServiceSearch on "+devList.length+" devices");
         
         UUID[] searchList = new UUID[2];
         
         searchList[0] = new UUID(0x0100);
          
          // This peace of code sometimes blocks the phone from getting the service (?)
          //int[] attributes = {0x100, 0x101, 0x102};
    
         searchList[1] = new UUID("F0E0D0C0B0A000908070605040302013", false);
         
         for (int i = 0; i < devList.length; i++) {
         
             
             try {
                 SEARCH_COMPLETED = false;
                 RemoteDevice tempDev = (RemoteDevice) devList[i];
                 discoveryAgent.searchServices(null, searchList, tempDev,this);
                
             } catch (BluetoothStateException btE) {
                 
                 log("ERROR!:"+btE.getMessage());
                 btE.printStackTrace();
             }
           /*
             synchronized (this) {
                 try {
                        log("Wait1/2");
                        this.wait();
                        
                 } catch (Exception e) {
                     
                        log("ERROR!:"+e.getMessage());
                        e.printStackTrace();
                 
                 }
             }*/
             
             log("Wait2/2");
             while (!SEARCH_COMPLETED){}        
             log("Donewait");
         }   
         
         DISCOVERY_COMPLETED = true;
         
         
        }
        
    
        public void servicesDiscovered(int transID, ServiceRecord[] servRecord) {
           
            log("Foundservice(" + transID+")");
            
            if (servRecord[0] == null) {
                log("The service record is null");
            }else {
                log("Add service to list");    
            
            /* This peace of code blocks on Siemens and Nokia
               Do you know a better/easier way to get the Service Name ?
             String str;
             log("getting service record");
             ServiceRecord sr = servRecord[0];
             log("getting att value");
             DataElement de = sr.getAttributeValue(0x100);
             log("Casting");
             str = (String) de.getValue();
             log("Service name:"+str);
             */
             
             if (serviceList!=null){
                serviceList.addElement(servRecord);
             }else
             {
                 log("ERROR:serviceList is null");
             }
                    
            }
            
        }
    
        public void serviceSearchCompleted(int transID, int respCode) {
            
           String msgLog ="ServiceSearchCompleted()" + transID + ", " + respCode;
    
           }
           
           SEARCH_COMPLETED = true;
           /*
           synchronized (this) {
                this.notify(); //works on Motorola & Siemens but not on Nokia(?)
            }*/
        }
        
        public void log(String msg){
            
            msg = "[BT]"+msg;
            parent.log(msg);
        }
    }

  2. #2
    Registered User
    Join Date
    Jul 2006
    Posts
    7

    Cool Re: 6630 Hangs up on Service Search :(

    I've solved the problem, using the JSR82 source code examples
    Aldo i haven't seen the differences yet...

  3. #3
    Registered User
    Join Date
    Oct 2007
    Posts
    2

    Re: 6630 Hangs up on Service Search :(

    can i see a part of code about how do u solve the problem ? Because I have the same one...
    Thanks
    magiuster.com, the REAL free realtime auction site! Help me, use it!

  4. #4
    Registered User
    Join Date
    Mar 2003
    Posts
    4,105
    Which one? Service name (forget and do not use it) or blocking of Nokia S60 (use a thread for nearly every call to the Bluetooth API)?

Similar Threads

  1. Replies: 4
    Last Post: 2006-09-05, 15:15
  2. help! 6630 doesn't publish service?
    By mantmarco in forum Mobile Java Networking & Messaging & Security
    Replies: 2
    Last Post: 2005-12-19, 06:58
  3. 6680 and bluetooth service profiles
    By ceruault in forum Mobile Java Networking & Messaging & Security
    Replies: 1
    Last Post: 2005-10-08, 22:24
  4. Service Search and 6600 problems!
    By carl404 in forum Bluetooth Technology
    Replies: 0
    Last Post: 2004-06-21, 16:27

Posting Permissions

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