可唔可以用BLUETOOTH 開SERVER

插入USE BLUETOOTH DONGLE, 是否開到SERVER?

開咩 server?

TOP

例如係PC做SERVER
手機可以SEND TEXT 俾PC

TOP

UUID uuid = new UUID("102030405060708090A0B0C0D0E0F011", false);
    String url = "btspp://localhost:" + uuid.toString();

// 1. create service record
      StreamConnectionNotifier n = (StreamConnectionNotifier) Connector.open(url);

TOP

原帖由 hungdennis 於 2008-12-21 18:20 發表
插入USE BLUETOOTH DONGLE, 是否開到SERVER?


廣義既server, 當然可以, 我都做過呢D solution...

TOP

StreamConnectionNotifier n = (StreamConnectionNotifier) Connector.open(url);

唔知點解open唔到

TOP

麻煩大家

TOP

冇 exception 出 ?

TOP

//
// a Date/Time server
// conn: RFCOMM
//

import java.io.*;
import javax.bluetooth.*;
import javax.microedition.io.*;
import java.util.*;

public class RFDateServ
{
  public static void main(String args[])
  {
    LocalDevice localdev = null;
    try {
      localdev = LocalDevice.getLocalDevice();
    } catch (BluetoothStateException e) {
      System.out.println("ERROR: cannot access local device");
      System.exit(1);
    }

    // show an example usage of getProperty.
    //System.out.println("MTU: " + localdev.getProperty(
    //                   "bluetooth.l2cap.receiveMTU.max"));

    UUID uuid = new UUID("102030405060708090A0B0C0D0E0F011", false);
    String url = "btspp://localhost:" + uuid.toString();

    try {
      // 1. create service record
      StreamConnectionNotifier n = (StreamConnectionNotifier) Connector.open(url);

      // 2. obtain the service record
      // set ServiceRecrod ServiceAvailability (0x0008) attribute to
      // indicate our service is available
      // 0xFF indicate fully available status
      // This operation is optional
      ServiceRecord record = localdev.getRecord(n);
      record.setAttributeValue( 0x0008, new DataElement( DataElement.U_INT_1,0xF
F ) );

      System.out.println("Waiting to be connected...");

      // 3.ready to accept connection: will block until a client connects
      StreamConnection conn = n.acceptAndOpen();

      // send and receive data
      String message = new Date().toString();
      InputStream is = conn.openInputStream();
      OutputStream os = conn.openOutputStream();
      os.write(message.getBytes());
      byte[] rbuf = new byte[100];
      is.read(rbuf);
      System.out.println("Received: " + new String(rbuf));
      is.close();
      os.close();
      conn.close();
    } catch (Exception e) {
      System.out.println("ERROR: connection failed.");
    }
  }
}


次次都出"ERROR: connection failed."

TOP

原帖由 hungdennis 於 2008-12-23 00:48 發表
//
// a Date/Time server
// conn: RFCOMM
//

import java.io.*;
import javax.bluetooth.*;
import javax.microedition.io.*;
import java.util.*;

public class RFDateServ
{
  public static void main(String ...


你用乜野電話試? 如果你用emulator 試, 你是否確定佢支援JSR-82?

TOP