Android Chinese API (--bluetoothserversocket[) bluetooth]
Source: Internet
Author: User
<span id="Label3"></p><p><p><strong>Objective</strong></p></p><p><p>This chapter is android.bluetooth.BluetoothServerSocket for the translation of the sections of the Android Bluetooth Section. Server communication sockets, similar to TCP Serversocket. Version for Android 2.3 r1, translated from Zhongshan University's "android Club sysu", Welcome to visit their wiki:http://www.android-wiki.net, thanks again for "android Club sysu"! Look forward to your participation in the Chinese translation of the Android API, contact me [email protected].</p></p><p><p></p></p><p><p><strong style="color: red;">Statement</strong></p></p><p><p>Welcome reprint, but please keep the original source of the article:)</p></p><p><p>Android Club sysu:http://www.android-wiki.net</p></p><p><p>Blog Park: http://www.cnblogs.com/</p></p><p><p>Android Chinese translation group: http://code.taobao.org/project/view/404/</p></p><p><p></p></p><p><p><strong>Body</strong></p></p><p><p>first, the structure</p></p><p style="text-align: left; text-indent: 21pt; margin-left: 21pt;" align="left"><p style="text-align: left; text-indent: 21pt; margin-left: 21pt;" align="left"><strong><em>Public final class <span style="color: #c00000;">Bluetoothserversocket extends <span style="color: #c00000;">Object implements <span style="color: #c00000;">closeable</span> </span> </span></em></strong></p></p><p style="margin-left: 21pt;" align="left"><p style="margin-left: 21pt;" align="left"></p></p><p style="text-align: left; text-indent: 21pt; margin-left: 21pt;" align="left"><p style="text-align: left; text-indent: 21pt; margin-left: 21pt;" align="left">Java.lang.Object</p></p><p style="text-align: left; text-indent: 21pt; margin-left: 42pt;" align="left"><p style="text-align: left; text-indent: 21pt; margin-left: 42pt;" align="left">Android.bluetooth.BluetoothServerSocket</p></p><p><p>Ii. Overview</p></p><p align="left"><p align="left"><span style="font-family: 宋体;">a Bluetooth listening port. </span></p></p><p align="left"><p align="left"> <span style="font-family: song body;"> Bluetooth port monitoring interface and tcp< Span style= "font-family: the song body;" > port similar: Socket<span style="font-family: arial," "> and Serversocket<span style=" font-family: the song body; "> class. On the server side, use Bluetoothserversocket<span style=" font-family: arial; " "class to create a <span> Listening service Port. When a connection is Bluetoothserversocket<span style="font-family: arial;"> accept, It will return a new Bluetoothsocket <span style="font-family: arial;" to manage the connection. at customer <span end, using a separate bluetoothsocket<span class initialize an external connection and < span></span></span></span></span></span></span></p></p><p align="left"><p align="left">the <span style="font-family: 宋体;">most commonly used Bluetooth port is Rfcomm<span style="font-family: 宋体;">, which is <span style="font-family: 宋体;">the type supported by the Android API. RFCOMM <span style="font-family: 宋体;">is a connection-oriented, data stream transmission via a Bluetooth module, which is also known as the serial port specification (Serial Port Profile<span style="font-family: 宋体;">, SPP<span style="font-family: 宋体;">). </span></span></span></span></span></span></p></p><p align="left"><span style="font-family: 宋体;">In order to create a new connection to be ready to listen<code><code><span style="font-size: 12pt;"><span style="font-family: ‘Calibri‘,‘sans-serif‘; font-size: 10.5pt;">BluetoothServerSocket</span></span></code></code><span style="font-family: 宋体;">class, using<code><code><span style="font-size: 12pt;"><span style="font-family: ‘Calibri‘,‘sans-serif‘; font-size: 10.5pt;">BluetoothAdapter.listenUsingRfcommWithServiceRecord()</span></span></code></code><span style="font-family: 宋体;">Method. and then call<code><code><span style="font-size: 12pt;"><span style="font-family: ‘Calibri‘,‘sans-serif‘; font-size: 10.5pt;">accept()</span></span></code></code><span style="font-family: 宋体;">method to monitor<span style="font-family: 宋体;">Listen to the Link's Request. The call is blocked until the connection is established, that is, it returns a<code><code><span style="font-size: 12pt;"><span style="font-family: ‘Calibri‘,‘sans-serif‘; font-size: 10.5pt;">BluetoothSocket</span></span></code></code><span style="font-family: 宋体;"><span style="font-family: arial;" class to manage the connection. after each acquisition of class, if you no longer need <span accept connection, it is best call <code> <span style="font-size:12pt;"><span style=" Font-family: ' Calibri ', ' Sans-serif '; font-size:10.5pt; ">bluetoothserversocket </span> </span> <span style="font-family: arial;" "category <code> <span style="font-size:12pt;"><span style="font-family: ' Calibri ', ' sans-serif '; font-size:10.5pt;">close () </span> </span> <span style="font-family: the song body;"> method. Close the <code> <span style="font-size:12pt;"><span style="font-family: ' Calibri ', ' Sans-serif '; font-size:10.5pt;" bluetoothserversocket < span> </span> </span></code> <span style="font-family: the song body;" the class does not close <span close this returned <code> <span style="font-size:12pt;"><span style="font-family: ' Calibri ', ' Sans-serif '; font-size:10.5pt;" bluetoothsocket < span> </span> <span style="font-family: arial;"> class. </span></span></span></span></span></span></span></span></span></span></span></span></p><p align="left"><p align="left"><code><span style="font-size: 12pt;"><span style="font-family: ‘Calibri‘,‘sans-serif‘; font-size: 10.5pt;">BluetoothSocket</span></span></code> <span style="font-family: 宋体;">class Thread Safety. In particular, the <code><span style="font-size: 12pt;"><span style="font-family: ‘Calibri‘,‘sans-serif‘; font-size: 10.5pt;">close()</span></span></code> <span style="font-family: 宋体;">method will always give up outside operations and shut down the server Port. </span></span></p></p><p align="left"><p align="left"><span style="font-family: 宋体;">note: you need <code><span style="font-size: 12pt;"><span style="font-family: ‘Calibri‘,‘sans-serif‘; font-size: 10.5pt;">BLUETOOTH</span></span></code> <span style="font-family: 宋体;">Permissions. </span></span></p></p><p align="left"><p align="left"><span style="font-family: 宋体;">See</span></p></p><p align="left"><p align="left"><code><span style="font-size: 12pt;"><span style="font-family: ‘Calibri‘,‘sans-serif‘; font-size: 10.5pt;">BluetoothSocket</span></span></code></p></p><p><p>Iii. Public methods</p></p><p><p><span style="font-family: ‘Calibri‘,‘sans-serif‘; font-size: 10.5pt; font-weight: normal;">public <span style="font-family: ‘Calibri‘,‘sans-serif‘; font-size: 10.5pt; font-weight: normal;"> <span style="background: #d9d9d9;">bluetoothsocket<span style="background: #d9d9d9; font-family: ‘Calibri‘,‘sans-serif‘; font-size: 10.5pt;">accept<span style="background: #d9d9d9; font-family: ‘Calibri‘,‘sans-serif‘; font-size: 10.5pt; font-weight: normal;"> (int timeout)</span> </span> </span></span></span></p></p><p align="left"><p align="left"><span style="font-family: 宋体;">the connection is blocked until the timeout period is Established. </span></p></p><p align="left"><p align="left"><span style="font-family: 宋体;">returns a connected Bluetoothsocket class on a successfully established connection <span style="font-family: 宋体;">. </span></span></p></p><p align="left"><p align="left"><span style="font-family: 宋体;">whenever the call returns, it can be called to receive a new connection Later. </span></p></p><p align="left"><p align="left"><code><span style="font-size: 12pt;"><span style="font-family: ‘Calibri‘,‘sans-serif‘; font-size: 10.5pt;">close()</span></span></code> <span style="font-family: 宋体;">method can be used to discard calls from another thread. </span></p></p><p align="left"><p align="left"><span style="font-family: 宋体;">Parameters</span></p></p><p align="left"><p align="left">Timeout <span style="font-family: 宋体;">(translator note: <span style="font-family: 宋体;">blocking Time-out)</span> </span></p></p><p align="left"><p align="left"><span style="font-family: 宋体;">return value</span></p></p><p align="left"><p align="left"><span style="font-family: 宋体;">Connected Bluetoothsocket</span></p></p><p align="left"><p align="left"><span style="font-family: 宋体;">Exception</span></p></p><p align="left"><p align="left">IOException an <span style="font-family: 宋体;">error occurred, such as the call was discarded, or timed Out. </span></p></p><p align="left"><p align="left"></p></p> <span style="font-family: ‘Calibri‘,‘sans-serif‘; font-size: 10.5pt; font-weight: normal;">public <span style="font-family: ‘Calibri‘,‘sans-serif‘; font-size: 10.5pt; font-weight: normal;"> <span style="background: #d9d9d9;">bluetoothsocket <span style="background: #d9d9d9; font-family: ‘Calibri‘,‘sans-serif‘; font-size: 10.5pt;">accept<span style="background: #d9d9d9; font-family: ‘Calibri‘,‘sans-serif‘; font-size: 10.5pt; font-weight: normal;"> ()</span> </span> </span> </span></span><p align="left"><p align="left"><span style="font-family: 宋体;">block until a connection has been established. (translator note: The default time-out is set To-1<span style="font-family: 宋体;">, see source Code)</span> </span></p></p><p align="left"><p align="left"><span style="font-family: 宋体;">returns a connected Bluetoothsocket class on a successfully established connection <span style="font-family: 宋体;">. </span></span></p></p><p align="left"><p align="left"><span style="font-family: 宋体;">whenever the call returns, it can be called to receive a new connection Later. </span></p></p><p align="left"><p align="left"><code><span style="font-size: 12pt;"><span style="font-family: ‘Calibri‘,‘sans-serif‘; font-size: 10.5pt;">close()</span></span></code> <span style="font-family: 宋体;">method can be used to discard calls from another thread. </span></p></p><p align="left"><p align="left"><span style="font-family: 宋体;">return value</span></p></p><p align="left"><p align="left"><span style="font-family: 宋体;">Connected Bluetoothsocket</span></p></p><p align="left"><p align="left"><span style="font-family: 宋体;">Exception</span></p></p><p align="left"><p align="left">IOException an <span style="font-family: 宋体;">error occurred, such as the call was discarded, or timed Out. </span></p></p><p align="left"><p align="left"></p></p><p style="text-align: left; text-indent: 21pt; margin-left: 21pt;" align="left"><p style="text-align: left; text-indent: 21pt; margin-left: 21pt;" align="left"><span style="background: #d9d9d9;">public void <strong>Close</strong> ()</span></p></p><p><p> <span style="font-family: 宋体;">Close the port immediately and release all related Resources.</span></p></p><p><p> <span style="font-family: 宋体;">Causes blocking in that port on other threads, causing the system to throw an IO <span style="font-family: 宋体;">exception immediately. </span></span></p></p><p><p> <span style="font-family: 宋体;">Closing Bluetoothserversocket <span style="font-family: 宋体;">does not turn off any bluetoothsocket that accept self-acceptance () <span style="font-family: 宋体;"><span style="font-family: 宋体;">. </span></span></span></span></p></p><p><p> <span style="font-family: 宋体;">Abnormal</span></p></p><p style="text-align: left; text-indent: 21pt; margin-left: 42pt;" align="left"><p style="text-align: left; text-indent: 21pt; margin-left: 42pt;" align="left">IOException</p></p><p><p></p></p><p><p>Android Chinese API (--bluetoothserversocket[) bluetooth]</p></p></span>
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service