Android Network Programming API packet-related interface API

Source: Internet
Author: User
Tags socket blocking

Android Network Programming related packages : 9 packets, 20 interfaces, 103 classes, 6 enumerations, 14 exceptions;

-- Java Package : Package (6 interfaces, 34 classes, 2 enumerations, 12 exceptions);

-- Android pack : Packets (1 interfaces, 19 classes, 3 enumerations, 1 exceptions), packets (6 classes), ANDROID.NET.NSD packets (3 interfaces, 2 classes), ANDROID.NET.RTP (4 classes), Andro ID.NET.SIP Packets (1 interfaces, 9 classes, 1 exceptions), packets (16 classes, 1 enumerations), ANDROID.NET.WIFI.P2P packets (9 interfaces, 7 classes), ANDROID.NET.WIFI.P2P.NSD packets ( Class 6);

contenthandlerfactory : The interface defines the content handler factory;

datagramsocketimplfactory : This interface defines the user datagram implementation factory;

fileNameMap : An interface that defines the mapping mechanism between a file name and a MIME Type string ;

socketimplfactory : Define socket Implementation factory;

socketoptions : Defines the interface that gets the method that sets the socket option ;

urlstreamhandlerfactory : Defines the URL stream protocol handler factory;

1. ContentHandlerFactory

role : Defines the content handler factory, which is responsible for mapping MIME types to ContentHandler instance objects;

MIME parsing :

-- extension : Multipurpose Internet Mail extentions Multi-purpose Internet Message extension type;

--- function : A file with a extension is opened using the B program, and when the a extension file is accessed, the browser automatically calls the B program to open the a extension file;

-- Use form : More for associating with custom file suffix file opening mode and media file open mode;

Interface Usage Environment : URLStreamHandler creates MIME Type ContentHandler using the method implemented by this interface;

interface Method Parsing :

ContentHandler Createcontenthandler (String mimetype)
-- function: Creates a new ContentHandler, which ContentHandler can read from the URLStreamHandler;

2. Datagramsocketimplfactory

function : Defines the factory used for the implementation of the packet sockets;

Interface Usage Environment : Datagramsocket Use this interface method to create a socket instance;

interface Method Parsing :

Datagramsocketimpl Createdatagramsocketimpl ()
-- function: Creating an Datagramsocketimpl instance object;

3. fileNameMap

function : The interface required for mapping between file names and MIME Type strings ;

interface Method Parsing :

String Getcontenttypefor (String fileName)
-- function: Gets the MIME Type string for the specified file name;

4. SocketImplFactory

function : Used to define sockets to implement the factory;

usage Environment : sockets and ServerSocket Use the method defined by this interface to create a socket instance;

Method Parsing :

SocketImpl Createsocketimpl ()
-- function: Create a new socket instance;

5. Socketoptions

function : Defines the method of setting the access socket option;

Interface Usage Environment : SocketImpl and Datagramsocketimpl Implement the interface, the subclass of the two classes should override this interface, to support the choice of subclass of two classes;

(1) Constant field parsing

ip_multicast_if : Set up an outgoing interface for sending multicast packets (eth0, eth1, wlan0, etc.);

-- using the environment : can be used on a host with multiple network interfaces , in this case the application does not use the system default interface, and the use of other interfaces;

IP Multicast : One host (multicast source) sends the same data to multiple hosts at the same time;

ip-multicast_if2 : The same as ip_multicast_if, but adds support for IPv4 IPV6, which is supported from version 1.4 ;

if_multicast_loop : Used to start or disable multicast datagrams sent, the default state is to start;

Ip_tos : Set the service type or traffic field of the TCP UDP datagram in the IP address header ;

TOS (type of service) : Prioritize packets in the network, single-byte, the following are common constant service types;

-- Iptos_lowdelay : Delay minimization;

-- Iptos_throughput : Optimizing throughput;

-- iptos_reliability : Reliability optimization;

-- iptos_mincost : Fill data, these data can be transmitted at low speed, insignificant;

so_bindaddr : Gets the local address of the bound socket;

--The socket local address cannot be changed : The socket is bound to the address at the time of creation and therefore cannot be changed;

-- Socket default address : Inaddr_any represents any address of a multi-homed host (host with multiple IP addresses);

so_reuseaddr : For MulticastSocket only, MulticastSocket set this option by default and is valid for Datagramsocketimpl;

so_broadcast : Start the processing ability to disable sending broadcast messages;

-- usage Scenarios : Datagram sockets, networks that support the concept of broadcast messages;

-- default setting : Datagramsocket the option to start by default;

so_keepalive : TCP sockets Set this option, the data is not transmitted through the Socket within 2 hours, TCP sends the KEEPALIVE probe to the same body;

-- function : Detect whether the host is crashed;

where applicable : only valid for TCP sockets;

-- the same bit through the expected ACK response : The application is not notified, after another 2 hours without data transmission, TCP continues to send a probe;

--The same bit through RST response : Notify the local TCP host crashed, shut down the socket restart host;

-- no response of the same body : close the socket directly;

so_linger : The timeout value for closing the stay, that is, the time to wait after the TCP Socket executes close;

-- enable a non-0 timeout value : Close () blocks until the transmit and confirm read and write is complete, forcing the shutdown through TCP RST if the timeout occurs;

-- Enable 0 timeout value : Close () will be forced to shut down, no wait;

so_oobinline : Whether to discard TCP emergency data received by the socket;

-- startup option : The TCP emergency data received by the socket is received through the socket input stream;

-- Disable option : The received TCP emergency data is discarded directly;

so_rcvbuf (receive) : Sets the buffer size of the network input ;

-- Set method use : Sets the size of the buffer used to receive data through the socket;

-- Gets the method used : Gets the receive data buffer size set by the socket;

-- applicable situation : SocketImpl, Datagramsocketimpl;

so_sndbuf (send): Set the base IO buffer size hint for the network output ;

-- Set method use : Sets the size of the buffer used when sending data through the socket;

-- Get method used : Gets the size of the send data buffer set by the socket;

-- applicable situation : SocketImpl, Datagramsocketimpl;

so_timeout : Sets the timeout value for Socket blocking;

-- timeout operation : Serversocket.accept (), (), datagramsocket.receive ();

-- Set timing : This option must be set before entering the block before it is valid, if it is blocked, the setting will not take effect for this block;

-- Timeout processing : If a timeout occurs, the block will continue to execute, but the interruptedioexception exception will be thrown, and the Socket will not be closed;

where applicable : This setting is valid for all sockets (SocketImpl, Datagramsocketimpl);

tcp_nodelay : Set the link of this parameter to disable the Nagle algorithm;

Nagle Algorithm Analysis : Reduce the number of packets, to increase the efficiency of the network software, to avoid a packet only 1 bytes, but the use of 40 bytes of the header file case;

(2) Detailed interface method

void setOption (int optid, Object value) throws SocketException
-- function : Enable/Disable the specified option, if enabled, the value option will be used;

-- option incoming error : If the incoming value is malformed, an error will occur;

-- incoming basic data type : Using an Integer Boolean package;

-- Disable option : Pass in New Boolean (false) to disable any options and enable this option if you pass in other content;

-- Exception : If the option matches the error, or the socket is closed and other errors, the socketexception exception will be reported;

Object getOption (int optid) throws SocketException
-- function: Gets the value of the option;

6. URLStreamHandlerFactory

interface Function : The factory that defines the URL stream protocol handler, and the URL class implements the interface to create the URLStreamHandler for the specific protocol;

Createurlstreamhandler URLStreamHandler Createurlstreamhandler (String protocol)
-- function: Creates a new URLStreamHandler instance with the specified protocol;

Related Article

Contact Us

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: 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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.