Package totalcross.net
Class SocketFactory
- java.lang.Object
-
- totalcross.net.SocketFactory
-
- Direct Known Subclasses:
SSLSocketFactory
public class SocketFactory extends java.lang.ObjectThis class creates sockets. It may be subclassed by other factories, which create particular subclasses of sockets and thus provide a general framework for the addition of public socket-level functionality. Socket factories are a simple way to capture a variety of policies related to the sockets being constructed, producing such sockets in a way which does not require special configuration of the code which asks for the sockets:- Due to polymorphism of both factories and sockets, different kinds of sockets can be used by the same application code just by passing it different kinds of factories.
- Factories can themselves be customized with parameters used in socket construction. So for example, factories could be customized to return sockets with different networking timeouts or security parameters already configured.
- The sockets returned to the application can be subclasses of java.net.Socket, so that they can directly expose new APIs for features such as compression, security, record marking, statistics collection, or firewall tunneling.
- Since:
- TotalCross 1.13
-
-
Constructor Summary
Constructors Constructor Description SocketFactory()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description SocketcreateSocket(java.lang.String host, int port)Creates a socket and connects it to the specified remote host at the specified remote port.SocketcreateSocket(java.lang.String host, int port, int timeout)Creates a socket and connects it to the specified remote host at the specified remote port.static SocketFactorygetDefault()
-
-
-
Method Detail
-
getDefault
public static SocketFactory getDefault()
-
createSocket
public Socket createSocket(java.lang.String host, int port) throws UnknownHostException, IOException
Creates a socket and connects it to the specified remote host at the specified remote port. This socket is configured using the socket options established for this factory.- Parameters:
host- the server hostport- the server port- Returns:
- the Socket
- Throws:
UnknownHostException- if the host is not knownIOException- if an I/O error occurs when creating the socket- Since:
- TotalCross 1.13
- See Also:
Socket(String, int)
-
createSocket
public Socket createSocket(java.lang.String host, int port, int timeout) throws UnknownHostException, IOException
Creates a socket and connects it to the specified remote host at the specified remote port. This socket is configured using the socket options established for this factory.- Parameters:
host- the server hostport- the server port- Returns:
- the Socket
- Throws:
UnknownHostException- if the host is not knownIOException- if an I/O error occurs when creating the socket- Since:
- TotalCross 1.22
- See Also:
Socket(String, int)
-
-