bluegammon.io
Interface BackgammonConnection

All Known Implementing Classes:
BackgammonBTConnection

public interface BackgammonConnection

This interface defines needed methods for connecting to another device on a remote backgammon game.

Author:
Peter Andersson

Method Summary
 void close()
          Closes all resources opened in this connection.
 boolean connectClient(java.lang.Object serverInfo)
          Connects a client to a server.
 javax.microedition.io.StreamConnection getConnection()
          If server has got a client or client is connected to a server, this method returns the connection.
 java.io.DataInputStream getInput()
          If server has got a client or client is connected to a server, this method returns the input stream.
 java.io.DataOutputStream getOutput()
          If server has got a client or client is connected to a server, this method returns the output stream.
 boolean isAwaitingClient()
          Returns true if this connection is awaiting a client already.
 boolean isClosed()
          Returns if this connection has been closed or not.
 void waitForClient()
          Opens a server and waits for client.
 

Method Detail

waitForClient

public void waitForClient()
                   throws java.io.IOException
Opens a server and waits for client. This method should block until a client connects or an IOException is thrown.

Throws:
java.io.IOException

isAwaitingClient

public boolean isAwaitingClient()
Returns true if this connection is awaiting a client already.

Returns:
True if awaiting client, false otherwise.

connectClient

public boolean connectClient(java.lang.Object serverInfo)
                      throws java.io.IOException
Connects a client to a server.

Parameters:
serverInfo - Any info needed to connect to the server.
Returns:
True if client connects successfully, false otherwise.
Throws:
java.io.IOException

getConnection

public javax.microedition.io.StreamConnection getConnection()
                                                     throws java.io.IOException
If server has got a client or client is connected to a server, this method returns the connection. Otherwise it returns null.

Returns:
The stream connection or null.
Throws:
java.io.IOException

getInput

public java.io.DataInputStream getInput()
If server has got a client or client is connected to a server, this method returns the input stream. Otherwise it returns null.

Returns:
the input stream or null.

getOutput

public java.io.DataOutputStream getOutput()
If server has got a client or client is connected to a server, this method returns the output stream. Otherwise it returns null.

Returns:
the output stream or null.

close

public void close()
           throws java.io.IOException
Closes all resources opened in this connection.

Throws:
java.io.IOException

isClosed

public boolean isClosed()
Returns if this connection has been closed or not.

Returns:
true if closed, false otherwise.