• BlackBerry Dynamics
  • Runtime library for Android applications
  • 12.0.1.79
SocketFactory Interface Reference

A factory for creating and connecting sockets. More...

Inheritance diagram for SocketFactory:
MultihomePlainSocketFactory LayeredSocketFactory PlainSocketFactory SSLSocketFactory

Description

The factory encapsulates the logic for establishing a socket connection.
Both java.lang.Object.equals(java.lang.Object) and java.lang.Object.hashCode() must be overridden for the correct operation of some connection managers.

Author
Roland Weber
Michael Becke
Mike Bowler

Notice

The following notice applies to the original API on which this API is based, and to its documentation. The documentation of this API has been revised from the original.

/*
 * Copyright (C) 2006 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

Public Member Functions

Socket connectSocket (Socket sock, String host, int port, InetAddress localAddress, int localPort, HttpParams params) throws IOException, UnknownHostException, ConnectTimeoutException
 Connects a socket to the given host. More...
 
Socket createSocket () throws IOException
 Creates a new, unconnected socket. More...
 
boolean isSecure (Socket sock) throws IllegalArgumentException
 Checks whether a socket provides a secure connection. More...
 

Member Function Documentation

◆ connectSocket()

Socket connectSocket ( Socket  sock,
String  host,
int  port,
InetAddress  localAddress,
int  localPort,
HttpParams  params 
) throws IOException, UnknownHostException, ConnectTimeoutException
Parameters
sockthe socket to connect, as obtained from createSocket . null indicates that a new socket should be created and connected.
hostthe host to connect to
portthe port to connect to on the host
localAddressthe local address to bind the socket to, or null for any
localPortthe port on the local machine, 0 or a negative number for any
paramsadditional parameters for connecting
Returns
the connected socket. The returned object may be different from the sock argument if this factory supports a layered protocol.
Exceptions
IOExceptionif an I/O error occurs
UnknownHostExceptionif the IP address of the target host can not be determined
ConnectTimeoutExceptionif the socket cannot be connected within the time limit defined in the params

Implemented in MultihomePlainSocketFactory, PlainSocketFactory, and SSLSocketFactory.

◆ createSocket()

Socket createSocket ( ) throws IOException
Returns
a new socket
Exceptions
IOExceptionif an I/O error occurs while creating the socket

Implemented in SSLSocketFactory, MultihomePlainSocketFactory, and PlainSocketFactory.

◆ isSecure()

boolean isSecure ( Socket  sock) throws IllegalArgumentException

The socket must be connected by this factory. The factory will not perform I/O operations in this method.
As a rule of thumb, plain sockets are not secure and TLS/SSL sockets are secure. However, there may be application specific deviations. For example, a plain socket to a host in the same intranet ("trusted zone") could be considered secure. On the other hand, a TLS/SSL socket could be considered insecure based on the cypher suite chosen for the connection.

Parameters
sockthe connected socket to check
Returns
true if the connection of the socket should be considered secure, or false if it should not
Exceptions
IllegalArgumentExceptionif the argument is invalid, for example because it is not a connected socket or was created by a different socket factory. Note that socket factories are not required to check these conditions, they may simply return a default value when called with an invalid socket argument.

Implemented in SSLSocketFactory, MultihomePlainSocketFactory, and PlainSocketFactory.