android-BluetoothServerSocket
2016-07-19 13:45
274 查看
BluetoothServerSocket
public final class BluetoothServerSocket
extends Object
implements Closeable
java.lang.Object | |
↳ | android.bluetooth.BluetoothServerSocket |
监听蓝牙socket。
The interface for Bluetooth Sockets is similar to that of TCP sockets:
Socketand
ServerSocket.
On the server side, use a
BluetoothServerSocketto create a listening
server socket. When a connection is accepted by the
BluetoothServerSocket,
it will return a new
BluetoothSocketto manage the connection. On the client
side, use a single
BluetoothSocketto 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
BluetoothServerSocketthat'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 a
BluetoothSocketto
manage the connection. Once the
BluetoothSocketis acquired, it's a good idea
to call
close()on the
BluetoothServerSocketwhen
it's no longer needed for accepting connections. Closing the
BluetoothServerSocketwill not close
the returned
BluetoothSocket.
创建一个倾听BluetoothServerSocket准备到达的连接,使用BluetoothAdapter.listenUsingRfcommWithServiceRecord()。然后调用accept()来侦听传入的连接请求。这个调用会阻塞,直到建立连接,此时,它将返回aBluetoothSocket管理连接。BluetoothSocket一旦获得,这是一个好主意叫关闭()BluetoothServerSocket时不再需要接受连接。关闭BluetoothSocket返回的BluetoothServerSocket不会关闭。
BluetoothServerSocketis thread safe. In particular,
close()will
always immediately abort ongoing operations and close the server socket.
BluetoothServerSocket是线程安全的。特别是,close()总是会立即中止正在进行的操作并关闭服务器套接字。
Note: Requires the
BLUETOOTHpermission.
Developer Guides
For more information about using Bluetooth, read the Bluetooth developerguide.
See also:
BluetoothSocket
Summary
| |
---|---|
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. |
|
---|
From class java.lang.Object |
From interface java.io.Closeable |
From interface java.lang.AutoCloseable |
Public methods
accept
Added in API level 5BluetoothSocket accept ()
Block until a connection is established.
Returns a connected
BluetoothSocketon
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.
Returns | |
---|---|
BluetoothSocket | a connected BluetoothSocket |
Throws | |
---|---|
IOException | on error, for example this call was aborted, or timeout |
accept
Added in API level 5BluetoothSocket accept (int timeout)
Block until a connection is established, with timeout.
Returns a connected
BluetoothSocketon
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.
Parameters | |
---|---|
timeout | int |
Returns | |
---|---|
BluetoothSocket | a connected BluetoothSocket |
Throws | |
---|---|
IOException | on error, for example this call was aborted, or timeout |
close
Added in API level 5void 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
BluetoothServerSocketwill not close
any
BluetoothSocketreceived from
accept().
Throws | |
---|---|
IOException |
toString
Added in API level 5String toString ()
Returns a string representation of the object. In general, the
toStringmethod 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
toStringmethod for class
Objectreturns 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())
Returns | |
---|---|
String | a string representation of the object. |
相关文章推荐
- Viewcontroller生命周期
- android-BluetoothSocket
- GUI界面,客户端向服务端传送文件
- Android开发技术周报 Issue#63
- uiautomator 仿 WebDriver 封装,页面工厂制作,实现多语言定位
- Android开发技术周报 Issue#64
- Android开发技术周报 Issue#65
- Android开发技术周报 Issue#66
- Android开发技术周报 Issue#67
- Android开发技术周报 Issue#68
- Android开发技术周报 Issue#70++
- Android开发技术周报 Issue#69
- Android开发技术周报 Issue#70
- Android开发技术周报 Issue#71
- [leetcode] 232. Implement Queue using Stacks
- Android开发技术周报 Issue#72
- Android开发技术周报 Issue#73
- IOS学习笔记-UITableView绑定数据实例
- Android开发技术周报 Issue#74
- Android开发技术周报 Issue#75