android-BluetoothServerSocket
来源:互联网 发布:考勤工资软件 编辑:程序博客网 时间:2024/06/07 21:13
BluetoothServerSocket
public final class BluetoothServerSocket
extends Object
implements Closeable
A listening Bluetooth socket.
监听蓝牙socket。
The interface for Bluetooth Sockets is similar to that of TCP sockets: Socket
and ServerSocket
. On the server side, use a BluetoothServerSocket
to create a listening server socket. When a connection is accepted by the BluetoothServerSocket
, it will return a new BluetoothSocket
to manage the connection. On the client side, use a single BluetoothSocket
to both initiate an outgoing connection and to manage the connection.
蓝牙Sockets 的接口是类似于TCP套接字:Sockets 和考察。在服务器端,使用BluetoothServerSocket创建一个监听服务器Sockets 。被BluetoothServerSocket接受连接时,它将返回一个新的BluetoothSocket管理连接。在客户端,使用单个BluetoothSocket发起一个即将离任的连接和管理连接。
The most common type of Bluetooth socket is RFCOMM, which is the type supported by the Android APIs. RFCOMM is a connection-oriented, streaming transport over Bluetooth. It is also known as the Serial Port Profile (SPP).
To create a listening BluetoothServerSocket
that's ready for incoming connections, use BluetoothAdapter.listenUsingRfcommWithServiceRecord()
. Then call accept()
to listen for incoming connection requests. This call will block until a connection is established, at which point, it will return aBluetoothSocket
to manage the connection. Once the BluetoothSocket
is acquired, it's a good idea to call close()
on the BluetoothServerSocket
when it's no longer needed for accepting connections. Closing the BluetoothServerSocket
will not close the returned BluetoothSocket
.
创建一个倾听BluetoothServerSocket准备到达的连接,使用BluetoothAdapter.listenUsingRfcommWithServiceRecord()。然后调用accept()来侦听传入的连接请求。这个调用会阻塞,直到建立连接,此时,它将返回aBluetoothSocket管理连接。BluetoothSocket一旦获得,这是一个好主意叫关闭()BluetoothServerSocket时不再需要接受连接。关闭BluetoothSocket返回的BluetoothServerSocket不会关闭。
BluetoothServerSocket
is thread safe. In particular, close()
will always immediately abort ongoing operations and close the server socket.
BluetoothServerSocket是线程安全的。特别是,close()总是会立即中止正在进行的操作并关闭服务器套接字。
Note: Requires the BLUETOOTH
permission.
Developer Guides
For more information about using Bluetooth, read the Bluetooth developer guide.
See also:
BluetoothSocket
Summary
Public methods
BluetoothSocket
accept()
Block until a connection is established.
阻塞直到建立连接。
BluetoothSocket
accept(int timeout)
Block until a connection is established, with timeout.阻塞直到建立连接,超时。
void
close()
Immediately close this socket, and release all associated resources.
String
toString()
Returns a string representation of the object.
Inherited methods
java.lang.Object
java.io.Closeable
java.lang.AutoCloseable
Public methods
accept
BluetoothSocket accept ()
Block until a connection is established.
Returns a connected BluetoothSocket
on successful connection.
Once this call returns, it can be called again to accept subsequent incoming connections.
close()
can be used to abort this call from another thread.
BluetoothSocket
a connected BluetoothSocket
IOException
on error, for example this call was aborted, or timeoutaccept
BluetoothSocket accept (int timeout)
Block until a connection is established, with timeout.
Returns a connected BluetoothSocket
on successful connection.
Once this call returns, it can be called again to accept subsequent incoming connections.
close()
can be used to abort this call from another thread.
timeout
int
BluetoothSocket
a connected BluetoothSocket
IOException
on error, for example this call was aborted, or timeoutclose
void close ()
Immediately close this socket, and release all associated resources.
Causes blocked calls on this socket in other threads to immediately throw an IOException.
Closing the BluetoothServerSocket
will not close any BluetoothSocket
received from accept()
.
IOException
toString
String toString ()
Returns a string representation of the object. In general, the toString
method returns a string that "textually represents" this object. The result should be a concise but informative representation that is easy for a person to read. It is recommended that all subclasses override this method.
The toString
method for class Object
returns a string consisting of the name of the class of which the object is an instance, the at-sign character `@
', and the unsigned hexadecimal representation of the hash code of the object. In other words, this method returns a string equal to the value of:
getClass().getName() + '@' + Integer.toHexString(hashCode())
String
a string representation of the object.- android-BluetoothServerSocket
- 【Android 应用开发】BluetoothServerSocket详解
- BluetoothServerSocket蓝牙解析
- BluetoothAdapter ;BluetoothDevice;BluetoothSocket;BluetoothServerSocket;UUID和String转换;
- Android
- android
- Android
- android
- android
- Android
- Android
- android
- android
- android
- Android
- Android
- android!!!
- android
- bzoj 2287(背包dp)
- PyMySQL-在Python 3.x下连接MySQL数据库的方法
- Python 小甲鱼教程 课后练习39
- vs2010安装“LNK1123: 转换到 COFF 期间失败: 文件无效或损坏”解决方法
- iOS应用程序内购/内付费(一)
- android-BluetoothServerSocket
- webstorn 快捷键
- MyEclipse2014安装jadeclipse插件
- 最简单的glut opengl程序
- 20. ubuntu 16.04 LTS 创建虚拟网卡
- IOS 知识小集(Status Bar变换)
- ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’
- New Document
- 关于数据库中无法插入中文(插入之后变成???)的解决办法