亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

目錄 搜索
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
文字


LocalSocket

?版本:Android 4.0 r1

?

結(jié)構(gòu)

繼承關(guān)系

public class LocalSocket extends Object

????????

java.lang.Object

android.net.LocalSocket

?

類概述

UNIX域名空間內(nèi)創(chuàng)建一個socket(非服務(wù)器),這種類型的socket完全不同于java.net.socket

?

構(gòu)造函數(shù)

public LocalSocket ()

???????? 創(chuàng)建一個AF_LOCAL/UNIX 套接字。

?

公共方法

public void bind (LocalSocketAddress bindpoint)

綁定socket到一個端口。僅可由還沒有被綁定的實(shí)體對象來調(diào)用該方法。

參數(shù)

bindpoint??? 端口地址

異常

IOException

?

public void close ()

關(guān)閉socket

異常

IOException

?

public void connect (LocalSocketAddress endpoint)

???????? 將當(dāng)前socket連接到一個端口,只有當(dāng)終端地址還沒有被連接的情況下才能調(diào)用該函數(shù)。

???????? 參數(shù)

endpoint???? 端口地址

???????? 異常

?????????????????? IOException???? 如果socket?是無效的或地址不存在。

?

public void connect (LocalSocketAddress endpoint, int timeout)

將當(dāng)前socket連接到一個端口。

異常

IOException???? 如果socket?是無效的或地址不存在

?

public FileDescriptor[] getAncillaryFileDescriptors()

獲取一組由對端通過附加消息傳送過來的文件描述符。這個方法會返回最近發(fā)送的文件描述符,并且返回空直到收到一個新的描述符文件描述符僅可以通過常規(guī)數(shù)據(jù)傳送,此方法讀取一個描述符后僅能返回非空值。

???????? 返回值

空或者文件描符數(shù)組

???????? 異常

IOException

?

public FileDescriptor getFileDescriptor ()

返回文件描述符,如果文件沒有打開或已關(guān)閉則返回空。

返回值

文件描述符或空

?

public InputStream getInputStream ()

?????????獲取輸入流。

???????? 返回值

input stream

???????? 異常

?????????????????socket已經(jīng)關(guān)閉或者還沒建立則拋出IO異常

public LocalSocketAddress getLocalSocketAddress ()

若存在則返回綁定的socket

???????? 返回值

?????????????????? 本地socket地址,若匿名則返回空。

?

public OutputStream getOutputStream ()

獲取輸出流

???????? 返回值

輸出

???????? 異常

?????????????????? socket已經(jīng)關(guān)閉或者還沒建立則拋出IO異常

?

public Credentials getPeerCredentials ()

獲取socket對的認(rèn)證信息。僅對已連接的套接字有效。

返回值

非空; 認(rèn)證信

???????? 異常

IOException

?

public int getReceiveBufferSize ()

(譯者注:獲取接受緩沖區(qū)大小)

???????? 異常

IOException

?

public LocalSocketAddress getRemoteSocketAddress()

(譯者注:獲取socket連接端地址)

?

public int getSendBufferSize ()

(譯者注:獲取發(fā)送緩沖區(qū)大?。?/span>

???????? 異常

IOException

?

public int getSoTimeout ()

(譯者注:得到遠(yuǎn)端超時設(shè)置)

???????? 異常

IOException

?

public synchronized boolean isBound ()

(譯者注:是否已經(jīng)綁定)

?

public boolean isClosed ()

(譯者注:是否已經(jīng)關(guān)閉連接)

?

public synchronized boolean isConnected ()

(譯者注:是否已連接)

?

public boolean isInputShutdown ()

(譯者注:輸入流是否已關(guān)閉)

?

public boolean isOutputShutdown ()

(譯者注:輸出流是否已關(guān)閉)

?

public void setFileDescriptorsForSend(FileDescriptor[] fds)

將一組文件描述符放入隊(duì)列準(zhǔn)備發(fā)送到對端(socket),這些文件描述符在下次發(fā)送普通數(shù)據(jù)時會作為單個輔助消息一同發(fā)送出去,請查看桌面linux 系統(tǒng)的“main 7 unix” SCM_RIGHT。

參數(shù)

Fds??????????? 非空,待發(fā)送的文件描述符數(shù)組。

?

public void setReceiveBufferSize (int size)

(譯者注:設(shè)置接受緩沖區(qū)大?。?/span>

???????? 異常

IOException

?

public void setSendBufferSize (int n)

(譯者注:設(shè)置發(fā)送緩沖區(qū)大小)

???????? 異常

IOException

?

public void setSoTimeout (int n)

(譯者注:設(shè)置遠(yuǎn)端超時設(shè)置)

???????? 異常

IOException

?

public void shutdownInput ()

關(guān)閉輸入端socket

???異常

???IOException

?

public void shutdownOutput ()

關(guān)閉輸出端socket

異常

IOException

?

?

補(bǔ)充?

文章精選

??? [推薦]OPhone OS的網(wǎng)絡(luò)層架構(gòu)介紹

示例代碼

??? Android LocalSocket / LocalServerSocket sample code

Platforms:?Android SDK 1.0 (Eclipse 3.4.1 + ADT 0.8.0)

main.xml

???<Button android:id="@+id/send_1_button"
??? ????????android:layout_width="fill_parent" android:layout_height="wrap_content"
???????????android:text="send 1 request"/>

?

java文件:

import java.io.IOException;
import java.io.InputStream;

import android.app.Activity;
import android.net.LocalServerSocket;
import android.net.LocalSocket;
import android.net.LocalSocketAddress;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;

/**
*
* @author Denis Migol
*
*/
public class DemoActivity extends Activity {
???
??? public static StringSOCKET_ADDRESS = "your.local.socket.address";
???
??? // background threads use this Handler to post messages to
??? // the main application thread
??? private final Handlerhandler = new Handler();
???
??? public class NotificationRunnable implements Runnable {
??????? private Stringmessage = null;
???????
??????? public void run() {
???????????if (message != null &&message.length() > 0) {
??????????????? showNotification(message);
???????????}
??????? }
???????
??????? /**
??????? * @param message the message to set
??????? */
??????? public voidsetMessage(String message) {
???????????this.message =message;
??????? }
??? }
???
??? // post this to the Handler when the background thread notifies
??? private final NotificationRunnablenotificationRunnable = new NotificationRunnable();
???
??? public voidshowNotification(String message) {
??????? Toast.makeText(this,message, Toast.LENGTH_SHORT).show();
??? }
???
??? class SocketListener extends Thread {
??????? private Handlerhandler = null;
??????? private NotificationRunnablerunnable = null;
???????
??????? public SocketListener(Handlerhandler, NotificationRunnablerunnable) {
???????????this.handler =handler;
???????????this.runnable =runnable;
???????????this.handler.post(this.runnable);
??????? }
???????
??????? /**
??????? * Show UI notification.
??????? * @param message
??????? */
??????? private voidshowMessage(String message) {
???????????this.runnable.setMessage(message);
???????????this.handler.post(this.runnable);
?????? ?}
???????
??????? @Override
??????? public void run() {
???????????//showMessage("DEMO: SocketListener started!");
???????????try {
???????????????LocalServerSocket server = new LocalServerSocket(SOCKET_ADDRESS);
???????????????while (true) {
?????? ?????????????LocalSocketreceiver = server.accept();
???????????????????if (receiver != null) {
???????????????????????InputStream input =receiver.getInputStream();
???????????????????????
???????????????????????// simply for java.util.ArrayList
???? ???????????????????intreaded = input.read();
???????????????????????int size = 0;
???????????????????????int capacity = 0;
???????????????????????byte[] bytes = new byte[capacity];
???????????????????????
???????????????????????// reading
?????????? ?????????????while (readed!= -1) {
???????????????????????????// java.util.ArrayList.Add(E e);
??????????????????????????? capacity = (capacity * 3)/2 + 1;
???????????????????????????//bytes = Arrays.copyOf(bytes, capacity);
???????????????????????????byte[] copy = new byte[capacity];
???????????????????????????System.arraycopy(bytes, 0, copy, 0, bytes.length);
??????????????????????????? bytes = copy;
??????????????????????????? bytes[size++] = (byte)readed;
???????????????????????????
????????????? ??????????????// read next byte
??????????????????????????? readed = input.read();
???????????????????????}
???????????????????????
??????????????????????? showMessage(new String(bytes, 0, size));
???????????????????}
???????????????}
???????????} catch (IOException e) {
???????????????Log.e(getClass().getName(), e.getMessage());
???????????}
??????? }
??? }
???
??? public static voidwriteSocket(String message) throws IOException {
??????? LocalSocketsender = new LocalSocket();
??????? sender.connect(new LocalSocketAddress(SOCKET_ADDRESS));
??????? sender.getOutputStream().write(message.getBytes());
??????? sender.getOutputStream().close();
??? }
???
??? @Override
??? public voidonCreate(Bundle savedInstanceState) {
??????? super.onCreate(savedInstanceState);
??????? setContentView(R.layout.main);
???????
??????? new SocketListener(this.handler, this.notificationRunnable).start();
???????
??????? Button send1= (Button)findViewById(R.id.send_1_button);
??????? send1.setOnClickListener(new OnClickListener() {
???????????
???????????@Override
???????????public void onClick(View v) {
???????????????try {
??????????????????? writeSocket("hello");
???????????????} catch (IOException e) {
???????????????????Log.e(getClass().getName(), e.getMessage());
???????????????}
???????????}
???????????
??????? });
??? }
}

????????

?


上一篇: 下一篇: