com.leafdigital.net.api
Interface Network

All Superinterfaces:
Singleton

public interface Network
extends Singleton

Network interface provides low-level networking features.


Nested Class Summary
static interface Network.Port
          A listening port.
 
Field Summary
static int SECURE_NONE
          SSL is not enabled for this connection.
static int SECURE_OPTIONAL
          SSL is optional for this connection; try SSL first, if it fails then try a normal connection.
static int SECURE_REQUIRED
          SSL is required for this connection.
 
Method Summary
 java.net.Socket connect(java.lang.String host, int port, int timeout)
          Connect to the given address using an insecure (non-SSL) connection and return a connected socket.
 java.net.Socket connect(java.lang.String host, int port, int timeout, int secureMode)
          Connect to the given address and return a connected socket.
 java.net.InetAddress getPublicAddress()
          Obtains the current public address.
 Network.Port listen()
          Open a public TCP port to listen for connections.
 Network.Port listen(java.lang.String remoteHost)
          Open a public TCP port to listen for connections from a specific host.
 boolean needsListenTarget()
           
 void reportPublicAddress(java.net.InetAddress ia)
          Report a possible public address that has been detected from another system (i.e. report from server).
 

Field Detail

SECURE_NONE

static final int SECURE_NONE
SSL is not enabled for this connection.

See Also:
Constant Field Values

SECURE_OPTIONAL

static final int SECURE_OPTIONAL
SSL is optional for this connection; try SSL first, if it fails then try a normal connection.

See Also:
Constant Field Values

SECURE_REQUIRED

static final int SECURE_REQUIRED
SSL is required for this connection.

See Also:
Constant Field Values
Method Detail

connect

java.net.Socket connect(java.lang.String host,
                        int port,
                        int timeout)
                        throws java.io.IOException
Connect to the given address using an insecure (non-SSL) connection and return a connected socket.

Parameters:
host - Host name or IP string
port - Port number
timeout - Timeout in milliseconds
Returns:
Connected socket
Throws:
java.io.IOException

connect

java.net.Socket connect(java.lang.String host,
                        int port,
                        int timeout,
                        int secureMode)
                        throws java.io.IOException
Connect to the given address and return a connected socket.

Parameters:
host - Host name or IP string
port - Port number
timeout - Timeout in milliseconds
secureMode - SECURE_xx constant
Returns:
Connected socket
Throws:
java.io.IOException

needsListenTarget

boolean needsListenTarget()
Returns:
True if the version of listen() with a target must be called

getPublicAddress

java.net.InetAddress getPublicAddress()
Obtains the current public address. Depending on connection settings and whether the user has connected to anything yet or not, this may very possibly be unknown and should not be relied on. The Port object, obtained when listening, always returns a valid public address and should be used instead of this for all practical purposes; this is just for display.

Returns:
The user's public address or null if not known

listen

Network.Port listen()
                    throws java.io.IOException
Open a public TCP port to listen for connections.

Returns:
Port ready for accept() calls
Throws:
java.io.IOException - If there are any problems creating the port

reportPublicAddress

void reportPublicAddress(java.net.InetAddress ia)
Report a possible public address that has been detected from another system (i.e. report from server). Should only be called if we are fairly confident about the address.

Parameters:
ia - Possible public address (will be ignored if it isn't)

listen

Network.Port listen(java.lang.String remoteHost)
                    throws java.io.IOException
Open a public TCP port to listen for connections from a specific host. (Must be called in some cases depending on user network settings.) Note that this does not necessarily provide a security feature; in some cases, the remote host will not be checked before being accepted.

Parameters:
remoteHost - Remote host address that will connect
Returns:
Port ready for accept() calls. Note that this version of the function returns a version which may only be accept()ed once.
Throws:
java.io.IOException - If there are any problems creating the port


Copyright © 2011 Samuel Marshall. All rights reserved.