us.ihmc.mockets
Class ServerMocket

java.lang.Object
  extended by us.ihmc.mockets.ServerMocket

public class ServerMocket
extends java.lang.Object

The main class for a server application to use the Mockets communication library. Similar in functionality to a server socket - used by a server to accept connections from client applications.


Constructor Summary
ServerMocket(int port)
          Creates a new ServerMocket and binds it to the specified port on localhost ready to accept incoming connections.
ServerMocket(int port, java.lang.String listenAddr)
          Creates a new ServerMocket and binds it to the specified address ready to accept incoming connections.
 
Method Summary
 Mocket accept()
          Listens for a connection to be made and accepts it.
 int close()
          Closes the current open connection to a remote endpoint.
protected  void finalize()
          Removes the ServerMocket object.
 java.lang.String getIdentifier()
          Returns the identifier for this mocket instance.
 int getLocalPort()
          Return the port where the ServerMocket is listening for connections.
 void setIdentifier(java.lang.String identifier)
          Sets a string to use as the application or user friendly identifier for this mocket instance.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ServerMocket

public ServerMocket(int port)
             throws java.io.IOException,
                    java.lang.IllegalArgumentException
Creates a new ServerMocket and binds it to the specified port on localhost ready to accept incoming connections. Specifying a value of 0 for the port causes a random port to be allocated.

Parameters:
port - integer value specifying the listening port. A value of 0 causes a random port to be allocated.
Throws:
java.io.IOException
java.lang.IllegalArgumentException

ServerMocket

public ServerMocket(int port,
                    java.lang.String listenAddr)
             throws java.io.IOException,
                    java.lang.IllegalArgumentException
Creates a new ServerMocket and binds it to the specified address ready to accept incoming connections. Specifying a value of 0 for the port causes a random port to be allocated.

Parameters:
port - integer value specifying the listening port. A value of 0 causes a random port to be allocated.
listenAddr - string value specifying the host's listening address. The hostname will be resolved.
Throws:
java.io.IOException
java.lang.IllegalArgumentException
Method Detail

getLocalPort

public int getLocalPort()
Return the port where the ServerMocket is listening for connections.

Returns:
port on which this ServerMocket is listening.

finalize

protected void finalize()
Removes the ServerMocket object.

Overrides:
finalize in class java.lang.Object

accept

public Mocket accept()
              throws java.io.IOException,
                     java.lang.IllegalArgumentException
Listens for a connection to be made and accepts it. A new Mocket is created.

Returns:
the new mocket created; NULL if an error occurred.
Throws:
java.io.IOException
java.lang.IllegalArgumentException

close

public int close()
          throws java.io.IOException,
                 java.lang.IllegalArgumentException
Closes the current open connection to a remote endpoint.

Returns:
0
Throws:
java.io.IOException
java.lang.IllegalArgumentException

setIdentifier

public void setIdentifier(java.lang.String identifier)
Sets a string to use as the application or user friendly identifier for this mocket instance. The identifier is used when sending out statistics and when logging information. Some suggestions include the name of the application, the purpose for this mocket, etc. May be set to NULL to clear a previously set identifier. NOTE: The string is copied internally, so the caller does not need to preserve the string

Parameters:
identifier - string to be used to identify this mocket instance.

getIdentifier

public java.lang.String getIdentifier()
Returns the identifier for this mocket instance.

Returns:
identifier of this mocket instance; NULL if no identifier is set.
See Also:
setIdentifier(java.lang.String)