蓝牙socket 通信思想提纲

蓝牙客户端通过BluetoothDevice创建BluetoothSocket并建立连接,使用inputStream和outputStream进行数据传输。服务端利用BluetoothAdapter监听连接,accept()方法处理并发连接。文章还提及了蓝牙设备发现和绑定的相关方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

蓝牙客户端Socket的与Sokcet流程是一样的。如下:

1、通过BluetoothDevicecreateRfcommSockettoServerRecord(UUID),创建客户端蓝牙BluetoothSokcet 
2BluetoothSokcet 的 connect 方法,创建连接 
3、通过 获取BluetoothSokcet 的 inputStream 、outputStream 读写数据 
4Socket 关闭。

服务端socket:

1、通过BluetoothAdapterlistenUsingRfcommWithServerSocket(name,UUID),创建服务端蓝牙BluetoothServerSocket 
2、通过调用 BluetoothServerSocketaccept(),如果有客户端连接,会创建一个新的 BluetoothSocket,体现出并发性,可以同时与多个socket通讯。 
3、通过 获取BluetoothSokcet 的  inputStream 、outputStream 读写数据 
4、关闭

常见蓝牙调用方法:

1BluetoothAdapter.getDefaultAdapter();
2、bluetoothAdapter.enable();
3、bluetoothAdapter.startDiscovery();(bluetoothAdapter.cancelDiscovery();4、广播:BluetoothDevice.ACTION_FOUNDBluetoothAdapter.ACTION_DISCOVERY_FINISHED
5Set<BluetoothDevice> devices = bluetoothAdapter.getBondedDevices();
6BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值