comm2j
Class Comm2J

java.lang.Object
  |
  +--comm2j.Comm2J

public class Comm2J
extends java.lang.Object

Comm2j is a class used to communicate with a Server (J2ME or J2SE), transmitting and receiving Messages.
It uses Read2J to communicate with the Server. Comm2J runs only on J2ME.
On J2SE you need to use just the Read2J.

Version:
1.0
Author:
Luca Bertoncello <lucabert@lucabert.de>
See Also:
MessageI, Read2J

Constructor Summary
Comm2J(javax.microedition.lcdui.CommandListener cmdListener, javax.microedition.lcdui.Display display, java.lang.String host, java.lang.String port)
          Constructor.
Save the connection data.
Comm2J(javax.microedition.lcdui.CommandListener cmdListener, javax.microedition.lcdui.Display display, java.lang.String host, java.lang.String port, int mode)
          Constructor.
Save the connection data.
 
Method Summary
 void connect()
          Connect to the remote host.
 void disconnect()
          Disconnect from the remote host.
 javax.microedition.lcdui.CommandListener getCommandListener()
          Returns the CommandListener used by Comm2J
 javax.microedition.io.Connection getConnection()
          Returns the connection link to the remote host ot null if not yet initialized.
 javax.microedition.lcdui.Display getDisplay()
          Returns the display used by Comm2J
 java.lang.String getHost()
          Returns the host used by Comm2j
 int getMode()
          Returns the mode used by Comm2J for the communication with the server
 java.lang.String getPort()
          Returns the port used by Comm2j
 boolean isConnected()
          Used to know if Comm2J has a valid link to the remote host
 Message readMessageFromStream()
          Receive a message from the remote host.
 void setCommandListener(javax.microedition.lcdui.CommandListener cmdListener)
          Sets the CommandListener used by Comm2J
 void setDisplay(javax.microedition.lcdui.Display display)
          Sets the display to be used by Comm2J
 void setHost(java.lang.String host)
          Sets the host used by Comm2j
 void setMode(int mode)
          Sets the mode used by Comm2J for the communication with the server
 void setPort(java.lang.String port)
          Sets the port used by Comm2j
 int writeMessageToStream(Message msg)
          Send a message to the remote host.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Comm2J

public Comm2J(javax.microedition.lcdui.CommandListener cmdListener,
              javax.microedition.lcdui.Display display,
              java.lang.String host,
              java.lang.String port)
Constructor.
Save the connection data. It's possibile to change them using set functions
Parameters:
cmdListener - CommandListener to be used to send commands
display - Display to be used to show data
host - Host to connect to
port - Port on the Host to connect to

Comm2J

public Comm2J(javax.microedition.lcdui.CommandListener cmdListener,
              javax.microedition.lcdui.Display display,
              java.lang.String host,
              java.lang.String port,
              int mode)
Constructor.
Save the connection data. It's possibile to change them using set functions
Parameters:
cmdListener - CommandListener to be used to send commands
display - Display to be used to show data
host - Host to connect to
port - Port on the Host to connect to
mode - Communication mode (RAW or COMPRESSED)
Method Detail

getCommandListener

public javax.microedition.lcdui.CommandListener getCommandListener()
Returns the CommandListener used by Comm2J
Returns:
Used CommandListener

setCommandListener

public void setCommandListener(javax.microedition.lcdui.CommandListener cmdListener)
Sets the CommandListener used by Comm2J
Parameters:
cmdListener - New CommandListener to be used

getDisplay

public javax.microedition.lcdui.Display getDisplay()
Returns the display used by Comm2J
Returns:
Current used display

setDisplay

public void setDisplay(javax.microedition.lcdui.Display display)
Sets the display to be used by Comm2J
Parameters:
display - New display to be used to show data

getMode

public int getMode()
Returns the mode used by Comm2J for the communication with the server
Returns:
Used communication mode
See Also:
Read2J

setMode

public void setMode(int mode)
Sets the mode used by Comm2J for the communication with the server
Parameters:
mode - New communication mode to be used
See Also:
Read2J

getHost

public java.lang.String getHost()
Returns the host used by Comm2j
Returns:
Current host to connect to

setHost

public void setHost(java.lang.String host)
Sets the host used by Comm2j
Parameters:
host - New host to connect to

getPort

public java.lang.String getPort()
Returns the port used by Comm2j
Returns:
Current port on the Host to connect to

setPort

public void setPort(java.lang.String port)
Sets the port used by Comm2j
Parameters:
port - New port on the Host to connect to

getConnection

public javax.microedition.io.Connection getConnection()
Returns the connection link to the remote host ot null if not yet initialized.
Returns:
Connection to the remote host

connect

public void connect()
Connect to the remote host. Print an error on Display if a connection problem occours

isConnected

public boolean isConnected()
Used to know if Comm2J has a valid link to the remote host
Returns:
true if valid link, false else

disconnect

public void disconnect()
Disconnect from the remote host. Print an error on Display if a disconnection problem occours

writeMessageToStream

public int writeMessageToStream(Message msg)
Send a message to the remote host. Print an error on Display if a communication problem occours
Parameters:
msg - Message to be sent
Returns:
number of sent bytes

readMessageFromStream

public Message readMessageFromStream()
Receive a message from the remote host. Print an error on Display if communication problem occours
Returns:
Message read from the remote host