一. BluetoorhServerSocket简介

1. 继承关系

public final class BluetoothServerSocket extends Object implements Closeable

继承了Object类, 实现了Closeable接口;

Closeable是可以关闭的数据源或者目标, 实现该接口必须重写close()方法, 调用close()方法可以释放该对象保存的资源;

2. 该类简介

使用BluetoothServerSocket可以创建一个监听服务端口, 使用accept()方法阻塞, 当该方法监测到连接的时候, 就会返回一个BluetoothSocket对象来管理这个连接, 例如获取输入输出流等;

RFCOMM端口是最常用的蓝牙端口, 该端口是面向连接的, 通过这个连接进行数据传输要遵守串口行为规范(Serial Port Profile, SPP);

该类用法 : BluetoothServerSocket对象时BluetoothAdapter对象调用listenUsingRfcommWithServiceRecord()方法, 调用accept()方法该方法就会将进程阻塞, 如果有BluetoothSock调用connect()方法连接到这个accept()中, 那个这个accept()方法就会返回一个BluetoothSocket对象;

调用BluetoothServerSocket方法的close()方法, 会释放该类占用的资源, 但是该类衍生出的BluetoothSocket对象不会被关闭;

二. 公共方介绍

(1)监听带超时连接

public BluetoothSocket accept (int timeout)

作用 : 该方法会阻塞, 知道监听到一个连接, 或者超时;

参数 : 阻塞时间;

返回值 : 监听到的BluetoothSocket连接;

(2)监听连接

public BluetoothSocket accept ()

作用 : 阻塞一直到连接建立;

返回值 : 监听到的BluetoothSocket连接;

(3)关闭端口

public void close ()

作用 : 关闭端口, 释放该端口占用的资源;

注意 : 如果这个端口在其它线程中accept()阻塞, 那么就会跑出异常, 关闭这个端口不会关闭accept()方法返回的BluetoothSocket对象;

BluetoothServerSocket详解的更多相关文章

  1. 【Android 应用开发】BluetoothServerSocket详解

    一. BluetoorhServerSocket简介 1. 继承关系 public final class BluetoothServerSocket extends Object implement ...

  2. 安卓程序代写 网上程序代写[原]BluetoothServerSocket详解

    一. BluetoorhServerSocket简介 1. 继承关系 public final class BluetoothServerSocket extends Object implement ...

  3. 【Android 应用开发】BluetoothSocket详解

    一. BluetoothSocket简介 1. 简介 客户端与服务端 : BluetoothSocket 和 BluetoothServerSocket 类似于Java中的套接字的 Socket 和 ...

  4. 【Android 应用开发】BluetoothDevice详解

    一. BluetoothDevice简介 1. 继承关系 public static Class BluetoothDevice extends Object implement Parcelable ...

  5. 安卓程序代写 网上程序代写[原]BluetoothSocket详解

    一. BluetoothSocket简介 1. 简介 客户端与服务端 : BluetoothSocket 和 BluetoothServerSocket 类似于Java中的套接字的 Socket 和 ...

  6. 安卓程序代写 网上程序代写[原]BluetoothDevice详解

    一. BluetoothDevice简介 1. 继承关系 public static Class BluetoothDevice extends Object implement Parcelable ...

  7. BluetoothSocket详解

    一. BluetoothSocket简介 1. 简介 客户端与服务端 : BluetoothSocket 和 BluetoothServerSocket 类似于Java中的套接字的 Socket 和 ...

  8. BluetoothDevice详解

    一. BluetoothDevice简介 1. 继承关系 public static Class BluetoothDevice extends Object implement Parcelable ...

  9. Android Developer -- Bluetooth篇 开发实例之四 API详解

    http://www.open-open.com/lib/view/open1390879771695.html 这篇文章将会详细解析BluetoothAdapter的详细api, 包括隐藏方法, 每 ...

随机推荐

  1. IO流,字符流

    import java.io.FileReader; public class FileReaderDemo { public static void main(String[] args) thro ...

  2. fake_useragent 封装好user-agent的模块

    from fake_useragent import UserAgent useragent = UserAgent()print(useragent.random)

  3. python教程(一)·命令行基本操作

    先来了解下 "命令提示符". 等等?!既然本篇文章标题是"命令行基本操作",那怎么又说到"命令提示符"去了呢?客官莫要急,且听我说 命令提示 ...

  4. C语言:一个数组中只有两个数字是出现一次

    //1.一个数组中只有两个数字是出现一次, //其他所有数字都出现了两次. //找出这两个数字,编程实现.a //^=单独两个数的^结果 //单独出现的两个数不同位的标记 //position: ^结 ...

  5. (转载)PHP环境搭建-记录

    PHP环境搭建-记录   转于 http://jingyan.baidu.com/article/fcb5aff797ec41edaa4a71c4.html php5.5 做了大量的更新,在与apac ...

  6. 爬取 StackOverFlow 上有关于 Python 的问题

    给定起始页面以及爬取页数,要求得到每一个问题的标题.票数.回答数.查看数 stackflow <- function(page){ url <- "http://stackove ...

  7. 【commons】字符串工具类——commons-lang3之StringUtils

    类似工具见Hutool-StrUtil 一.起步 引入maven依赖 <!-- https://mvnrepository.com/artifact/org.apache.commons/com ...

  8. Java基础——NIO(二)非阻塞式网络通信与NIO2新增类库

    一.NIO非阻塞式网络通信 1.阻塞与非阻塞的概念  传统的 IO 流都是阻塞式的.也就是说,当一个线程调用 read() 或 write() 时,该线程被阻塞,直到有一些数据被读取或写入,该线程在 ...

  9. MapWindow介绍

    官方网站:http://www.mapwindow.org/ 网站里包含了几个开源项目 目前最新版本是Mapwindow5,之前的mapwindow4版本已经停止更新,同时Mapwindow5底层是调 ...

  10. 利尔达NB-IOT模组Coap数据AT+NMGS发送时返回-513的原因

    1. 利尔达NB-IOT模组使用AT+NMGS发送数据,返回-513的问题,大致有3种可能性,在硬件上,模组的射频电路分为A型和B型模组,所以烧写固件的时候,也要分为A和B型固件,如果烧写反了,那么R ...