directory search
android Manifest Manifest.permission Manifest.permission_group android.accessibilityservice AccessibilityService android.accounts Account android.app NotificationManager android.bluetooth BluetoothAdapter BluetoothClass BluetoothClass.Device BluetoothClass.Device.Major BluetoothClass.Service BluetoothDevice BluetoothServerSocket BluetoothSocket android.content SharedPreferences android.database.sqlite SQLiteCursorDriver SQLiteOpenHelper android.graphics Bitmap android.location LocationListener Geocoder GpsStatus GpsStatus.Listener GpsStatus.NmeaListener GpsSatellite android.media AudioFormat AsyncPlayer AudioRecord AudioRecord.OnRecordPositionUpdateListener ThumbnailUtils AudioManager android.net TrafficStats MailTo LocalSocket android.os AsyncTask AsyncTask.Status CountDownTimer Message MessageQueue HandlerThread android.text Html android.util JsonWriter android.view ContextMenu ContextMenu.ContextMenuInfo Display ViewManager View ViewStub ViewTreeObserver ViewParent WindowManager GestureDetector Gravity MenuInflater ScaleGestureDetector SoundEffectConstants android.view.inputmethod InputConnection InputMethod InputMethodSession BaseInputConnection InputMethodManager android.widget AbsListView AbsListView.LayoutParams AbsListView.OnScrollListener AbsListView.RecyclerListener AbsoluteLayout AbsoluteLayout.LayoutParams AbsSeekBar AbsSpinner AdapterView AdapterView.AdapterContextMenuInfo AdapterView.OnItemLongClickListener AdapterView.OnItemSelectedListener AdapterView.OnItemClickListener AnalogClock BaseAdapter BaseExpandableListAdapter Button CheckBox CheckedTextView Checkable Chronometer Chronometer.OnChronometerTickListener CompoundButton CompoundButton.OnCheckedChangeListener CursorAdapter CursorTreeAdapter DatePicker DatePicker.OnDateChangedListener DialerFilter DigitalClock EditText Filter Filter.FilterListener Filter.FilterResults ExpandableListAdapter ExpandableListView.OnChildClickListener ExpandableListView.OnGroupClickListener ExpandableListView.OnGroupCollapseListener ExpandableListView.OnGroupExpandListener Filterable Gallery Gallery.LayoutParams GridView GridLayout GridLayout.Alignment RadioGroup ImageView ImageView.ScaleType HorizontalScrollView ImageButton ImageSwitcher FilterQueryProvider ListAdapter ListView MediaController MultiAutoCompleteTextView MultiAutoCompleteTextView.CommaTokenizer MultiAutoCompleteTextView.Tokenizer QuickContactBadge RadioButton RatingBar RatingBar.OnRatingBarChangeListener RelativeLayout RemoteViews ResourceCursorAdapter ResourceCursorTreeAdapter Scroller ScrollView SearchView SearchView.OnCloseListener SearchView.OnQueryTextListener SearchView.OnSuggestionListener SeekBar SeekBar.OnSeekBarChangeListener SimpleAdapter SimpleAdapter.ViewBinder SimpleCursorAdapter SimpleCursorAdapter.CursorToStringConverter SimpleCursorAdapter.ViewBinder SimpleCursorTreeAdapter SimpleCursorTreeAdapter.ViewBinder SimpleExpandableListAdapter SlidingDrawer SlidingDrawer.OnDrawerCloseListener SlidingDrawer.OnDrawerOpenListener SlidingDrawer.OnDrawerScrollListener Spinner SpinnerAdapter WrapperListAdapter TabHost TabHost.TabSpec TextView TimePicker TimePicker.OnTimeChangedListener Toast TableLayout TableLayout.LayoutParams TableRow TableRow.LayoutParams TabWidget TextSwitcher ToggleButton TwoLineListItem VideoView ViewAnimator ViewFlipper ViewSwitcher ViewSwitcher.ViewFactory ZoomButtonsController ZoomButtonsController.OnZoomListener ZoomButton ZoomControls dalvik.system DexFile
characters


BluetoothServerSocket

版本:Android 2.3 r1

 

结构

继承关系

public final class BluetoothServerSocket extends Object implements Closeable

        

java.lang.Object

android.bluetooth.BluetoothServerSocket

 

类概述

         一个蓝牙监听端口。

         蓝牙端口监听接口和TCP端口类似:SocketServerSocket类。在服务器端,使用BluetoothServerSocket类来创建一个 监听服务端口。当一个连接被BluetoothServerSocket所接受,它会返回一个新的BluetoothSocket来管理该连接。在客户 端,使用一个单独的BluetoothSocket类去初始化一个外接连接和管理该连接。

         最通常使用的蓝牙端口是RFCOMM,它是被Android API支持的类型。RFCOMM是一个面向连接,通过蓝牙模块进行的数据流传输方式,它也被称为串行端口规范(Serial Port ProfileSPP)。

         为了创建一个对准备好的新来的连接去进行监听BluetoothServerSocket类,使用 BluetoothAdapter.listenUsingRfcommWithServiceRecord()方法。然后调用accept()方法去监 听该链接的请求。在连接建立之前,该调用会被阻断,也就是说,它将返回一个BluetoothSocket类去管理该连接。每次获得该类之后,如果不再需 要接受连接,最好调用在BluetoothServerSocket类下的close()方法。关闭BluetoothServerSocket类不会关 闭这个已经返回的BluetoothSocket类。

         BluetoothSocket类线程安全。特别的,close()方法总会马上放弃外界操作并关闭服务器端口。

         注意:需要BLUETOOTH权限。

         参见

                   BluetoothSocket

 

公共方法

public BluetoothSocket accept (int timeout)

         阻塞直到超时时间内的连接建立。

         在一个成功建立的连接上返回一个已连接的BluetoothSocket类。

         每当该调用返回的时候,它可以在此调用去接收以后新来的连接。

         close()方法可以用来放弃从另一线程来的调用。

                   参数

                            timeout    (译者注:阻塞超时时间)

                   返回值

                            已连接的 BluetoothSocket

                   异常

                            IOException     出现错误,比如该调用被放弃,或者超时。

 

public BluetoothSocket accept ()

         阻塞直到一个连接已经建立。(译者注:默认超时时间设置为-1,见源码)

         在一个成功建立的连接上返回一个已连接的BluetoothSocket类。

         每当该调用返回的时候,它可以在此调用去接收以后新来的连接。

         close()方法可以用来放弃从另一线程来的调用。

                   返回值

                            已连接的 BluetoothSocket

                   异常

                            IOException     出现错误,比如该调用被放弃,或者超时。

 

         public void close ()

马上关闭端口,并释放所有相关的资源。

在其他线程的该端口中引起阻塞,从而使系统马上抛出一个IO异常。

关闭BluetoothServerSocket不会关闭接受自accept()的任意BluetoothSocket

异常

IOException


Previous article: Next article: