×

Discussion Board

Results 1 to 4 of 4
  1. #1
    Regular Contributor
    Join Date
    Nov 2006
    Location
    Brebes, Indonesia
    Posts
    129

    Bkuetooth ConnectionString

    Some one can help me, i have problem with blutooth connection string.

    I have code
    Server
    BtHandler.java

    Code:
    import javax.microedition.xml.rpc.Operation;
    import javax.obex.ResponseCodes;
    import javax.obex.ServerRequestHandler;
    
    /**
     *
     * @author Hendrawan
     */
    public class BtHandler extends ServerRequestHandler  {
        public BtHandler() {
    
        }
        
        public int onPut(Operation op) {
            return ResponseCodes.OBEX_HTTP_OK;
        }
    
    }
    bluetoothserver.java

    Code:
    import java.io.IOException;
    import javax.bluetooth.BluetoothStateException;
    import javax.bluetooth.DiscoveryAgent;
    import javax.bluetooth.LocalDevice;
    import javax.bluetooth.UUID;
    import javax.microedition.io.Connector;
    import javax.obex.SessionNotifier;
    
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    
    /**
     *
     * @author Hendrawan
     */
    public class BluetoothServer implements Runnable {
        private boolean listening = true;
        private LocalDevice local_device;
        private HelloMIDlet midlet;    
        //private L2CAPConnection con;
        private SessionNotifier notifier;
        private BtHandler aBtHandler = new BtHandler();   
        private UUID uuid = null;
        private String deviceName;
        
        /** Creates a new instance of BluetoothServer */
        public BluetoothServer(HelloMIDlet midlet) {
            this.midlet = midlet;
            Thread t = new Thread(this);
            t.start();
        }
    
        public void run(){        
            midlet.SetMessage("Starting Server");
            try {
                local_device = LocalDevice.getLocalDevice();            
                local_device.setDiscoverable(DiscoveryAgent.LIAC);                        
                uuid = new UUID("9", false);
                deviceName = local_device.getFriendlyName();
                
                String url = "btl2cap://localhost:" + uuid + ";name=" + deviceName;
                
                
                 notifier = ( SessionNotifier ) Connector.open(url);
                midlet.SetMessage("Server started with conn " + url);            
                notifier.acceptAndOpen(aBtHandler);
                midlet.SetMessage("Connection receive");
                
                /*while (listening) {
                    if (con.ready()){
                        midlet.SetMessage("Connection receive");
                        byte[] b = new byte[1000];
                        con.receive(b);
                        String s = new String(b, 0, b.length);
                        System.out.println("Recieved from client: " + s.trim());
                        midlet.SetMessage(s.trim());
                        send("Hello client, my name is: " + getName());
                        listening=false;
                    }
                }*/
    
            } catch(BluetoothStateException e){System.out.println(e);} catch(IOException f){System.out.println(f);}
        }    
    }
    Client
    BluetoothClient.java

    Code:
    import java.io.IOException;
    import java.util.Vector;
    import javax.bluetooth.BluetoothStateException;
    import javax.bluetooth.DeviceClass;
    import javax.bluetooth.DiscoveryAgent;
    import javax.bluetooth.DiscoveryListener;
    import javax.bluetooth.LocalDevice;
    import javax.bluetooth.RemoteDevice;
    import javax.bluetooth.ServiceRecord;
    import javax.bluetooth.UUID;
    import javax.obex.ClientSession;
    import javax.obex.HeaderSet;
    
    /**
     *
     * @author Hendrawan
     */
    public class BluetoothClient implements DiscoveryListener {
        LocalDevice local = null;
        DiscoveryAgent agent = null;
        int[] attrSet = null;
        RemoteDevice btDev = null;
        String serviceURL = null;
        ClientSession con = null;
        HeaderSet hdr = null;
        HelloMIDlet aView = null;
        private Vector devicesVector;
    
        public BluetoothClient(HelloMIDlet view) throws BluetoothStateException{
            // initialize the stack, if needed
            local = LocalDevice.getLocalDevice();
            agent = local.getDiscoveryAgent();
            agent.startInquiry(DiscoveryAgent.GIAC, this);
            devicesVector = new Vector();
            
            aView = view;
            aView.showAlert("Starting Client..");
        }
    
        public void ConnectingDevice(int aIndex) {
            btDev = (RemoteDevice) devicesVector.elementAt(aIndex);
            
            UUID[] uuids = new UUID[1];
            uuids[0] = new UUID("9", false);
            try {
                agent.searchServices(attrSet, uuids, btDev, this);
            } catch (Exception ex) {
                aView.showAlert(ex.getMessage().toString());
            }
        }
        
        public void deviceDiscovered(RemoteDevice btDevice, DeviceClass cod) {        
            try {
                devicesVector.addElement(btDevice);
                aView.setMessage(btDevice.getFriendlyName(false));
            } catch (IOException ex) {
                ex.printStackTrace();
            }
            throw new UnsupportedOperationException("Not supported yet.");
        }
    
        public void inquiryCompleted(int discType) {
            aView.showAlert("Searching device complete");
            throw new UnsupportedOperationException("Not supported yet.");
        }
    
        public void servicesDiscovered(int transID, ServiceRecord[] servRecord) {
            //aView.showAlert(Integer.toString(servRecord.length));
            for(int i =0; i < servRecord.length; i++){
                serviceURL = servRecord[i].getConnectionURL(ServiceRecord.NOAUTHENTICATE_NOENCRYPT,true);
            }
            throw new UnsupportedOperationException("Not supported yet.");
        }
    
        public void serviceSearchCompleted(int transID, int respCode) {
            // connection string always null
            aView.showAlert("Service discover finish, url:" + serviceURL);
            /*try {
                con = (ClientSession)Connector.open(serviceURL);
            } catch (Exception ex) {
            }*/
            throw new UnsupportedOperationException("Not supported yet.");
        }
    }
    All proses runing well, but i can't get connection string to create connection to server. Please help me, thanks for responses

    Nb
    i am using Symbia 3rd FP1 ME SDK, and 6120Clasic as device.
    http://blogehendrawan.blogspot.com - Kembangin symbian di Indonesia yukk....

  2. #2
    Registered User
    Join Date
    Mar 2003
    Posts
    4,105
    Is there a reason to go for such a short UUID like 9? Have you tried a long private one already?

  3. #3
    Regular Contributor
    Join Date
    Nov 2006
    Location
    Brebes, Indonesia
    Posts
    129

    Re: Bkuetooth ConnectionString

    yes i have try
    private final static UUID uuid = new UUID("A55665EE9F9146109085C2055C888B38", false);

    but same.
    http://blogehendrawan.blogspot.com - Kembangin symbian di Indonesia yukk....

  4. #4
    Registered User
    Join Date
    Mar 2003
    Posts
    4,105
    Do you get an exception, where? Or, is not found any service? Are you sure your service is advertised? As you are connection to an emulator, is it connected to a real Bluetooth adapter?

Similar Threads

  1. bkuetooth accuracy
    By meikei in forum Bluetooth Technology
    Replies: 2
    Last Post: 2008-10-18, 18:32

Posting Permissions

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