Results 1 to 1 of 1
Thread: Java Bluetooth ?
Hybrid View
-
6th January 2011 20:21 #1
Java Bluetooth ?
Java - Bluetooth? , , - , , ( ). - -> http://wiki.forum.nokia.com/index.ph...hat_HelloWorld
exception-
. PC . (Server-a PC-, ), at com.sun.kvem.jsr082.bluetooth.LocalDevic eImpl.<init>(LocalDeviceImpl.java:184) ( ). , , LocalDevice.getLocalDevice(); local_device.getDiscoveryAgent(); 6-7 100+ ( ).
, java ->
Code:import java.io.IOException; import javax.bluetooth.BluetoothStateException; import javax.bluetooth.DiscoveryAgent; import javax.bluetooth.L2CAPConnection; import javax.bluetooth.L2CAPConnectionNotifier; import javax.bluetooth.LocalDevice; import javax.microedition.io.Connector; public class Testing { private static boolean listening = true; private static LocalDevice local_device; private static String deviceName; private static L2CAPConnection con; private static void send(String s){ byte[] b = s.getBytes(); try { con.send(b); } catch(IOException e){ System.out.println(e); } } private static String getName(){ return deviceName; } public static void main(String[] args) { System.out.println("Starting server - please wait..."); try { local_device = LocalDevice.getLocalDevice(); local_device.setDiscoverable(DiscoveryAgent.LIAC); DiscoveryAgent disc_agent = local_device.getDiscoveryAgent(); //local_device.setDiscoverable(DiscoveryAgent.LIAC); String service_UUID = "00000000000010008000006057028A06"; deviceName = local_device.getFriendlyName(); String url = "btl2cap://localhost:" + service_UUID + ";name=" + deviceName; L2CAPConnectionNotifier notifier = (L2CAPConnectionNotifier)Connector.open(url); con = notifier.acceptAndOpen(); while (listening) { if (con.ready()){ 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.setAlert(s.trim()); send("Hello client, my name is: " + getName()); listening=false; } } } catch(BluetoothStateException e){System.out.println("BTStateException -> "); e.printStackTrace();} catch(IOException f){System.out.println("IOexception -> "); f.printStackTrace();} } }MSI X570-A PRO, AMD 5800X3D, Noctua NH-D15, Corsair Vengeance LPX 2x8GB-3600, ASUS RTX ROG 3080 Strix White OC, Samsung 980 Pro 1TB NVMe, Corsair RM750, FD Define R5, Dell 32" 4k G3223Q 144Hz + 3xSamsung G5 32" 144hz, SimLab P1-X, Simucube 2 Pro, HE Ultimate, SRB GT3 Wheel




Reply With Quote
Lenovo ThinkPad 15 IdeaPad 15
5th May 2023, 22:16 in