Some one can help me, i have problem with blutooth connection string.
I have code
Server
BtHandler.java
bluetoothserver.javaCode: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; } }
ClientCode: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);} } }
BluetoothClient.java
All proses runing well, but i can't get connection string to create connection to server. Please help me, thanks for responsesCode: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."); } }
Nb
i am using Symbia 3rd FP1 ME SDK, and 6120Clasic as device.


Reply With Quote

