Package javax.bluetooth

Examples of javax.bluetooth.L2CAPConnection


        /**
         * @see java.lang.Runnable#run()
         */
        public void run() {
            try {
                L2CAPConnection connection = null;
                try {
                    final UUID uuid = new UUID(_uuid);
                    final LocalDevice local = LocalDevice.getLocalDevice();
                    updateStatus("[SERVER] Device Address: "
                            + local.getBluetoothAddress());
                    updateStatus("[SERVER] Device Name: "
                            + local.getFriendlyName());
                    updateStatus("[SERVER] Listening for Client...");

                    // Open a connection and wait for client requests
                    final L2CAPConnectionNotifier service =
                            (L2CAPConnectionNotifier) Connector
                                    .open("btl2cap://localhost:" + uuid
                                            + ";name=" + SERVICE_NAME_L2CAP);
                    connection = service.acceptAndOpen();
                    updateStatus("[SERVER] L2CAP connection established");

                    // Read a message
                    final byte[] buffer = new byte[1024];
                    final int readBytes = connection.receive(buffer);
                    final String receivedMessage =
                            new String(buffer, 0, readBytes);
                    updateStatus("[SERVER] Message received: "
                            + receivedMessage);

                    // Send a message
                    final String message = "\nJSR-82 SERVER says hello!";
                    updateStatus("[SERVER] Sending message....");
                    connection.send(message.getBytes());
                } finally {
                    connection.close();
                    updateStatus("[SERVER] L2CAP session closed");
                }
            } catch (final IOException ioe) {
                BluetoothJSR82Demo.errorDialog(ioe.toString());
            }
View Full Code Here


        /**
         * @see java.lang.Runnable#run()
         */
        public void run() {
            try {
                L2CAPConnection connection = null;
                try {
                    // Send the server a request to open a connection
                    connection = (L2CAPConnection) Connector.open(_url);
                    updateStatus("[ClIENT] L2CAP session created");

                    // Send a message to the server
                    final String message =
                            "\n[CLIENT] JSR-82 CLIENT says hello!";
                    updateStatus("Sending message....");
                    connection.send(message.getBytes());

                    // Read a message
                    final byte[] buffer = new byte[1024];
                    final int readBytes = connection.receive(buffer);
                    final String receivedMessage =
                            new String(buffer, 0, readBytes);
                    updateStatus("[CLIENT] Message received: "
                            + receivedMessage);
                } finally {
                    connection.close();
                    updateStatus("[ClIENT] L2CAP session closed");
                }
            } catch (final IOException ioe) {
                BluetoothJSR82Demo.errorDialog(ioe.toString());
            }
View Full Code Here

TOP

Related Classes of javax.bluetooth.L2CAPConnection

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.