com.funambol.platform
Class SocketAdapter

java.lang.Object
  extended by com.funambol.platform.SocketAdapter

public class SocketAdapter
extends java.lang.Object

This class is a proxy to javax.microedition.io.SocketConnection to provide a common access to a socket resource on all mobile platforms. A portable code must use this class only to use sockets, and must take care of closing the SocketAdapter when not used anymore.

 Example:
 
   void socketAccessExample(String host, int port) {
      SocketAdapter sa = new SocketAdapter(host, port); // opens the SocketConnection
      InputStream is = sa.openInputStream();  // opens the InputStream
      while( (char c = is.read()) != -1) {    // read till the end of the file
         System.out.print(c);
      }
      is.close();                             // closes the InputStream
      sa.close();                             // closes the SocketConnection
 


Field Summary
static byte DELAY
           
static byte KEEPALIVE
           
static byte LINGER
           
static byte RCVBUF
           
static int READ_WRITE
           
static byte SNDBUF
           
 
Constructor Summary
SocketAdapter(java.lang.String host, int port, int mode, boolean timeout)
          Creates a FileAdapter instance, opening the underlying SocketConnection.
 
Method Summary
 void close()
          Close this Socket
 java.io.InputStream openInputStream()
          Open and return an input stream for this Socket.
 java.io.OutputStream openOutputStream()
          Open and return an output stream for this Socket.
 void setSocketOption(byte option, int value)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DELAY

public static final byte DELAY
See Also:
Constant Field Values

KEEPALIVE

public static final byte KEEPALIVE
See Also:
Constant Field Values

LINGER

public static final byte LINGER
See Also:
Constant Field Values

RCVBUF

public static final byte RCVBUF
See Also:
Constant Field Values

SNDBUF

public static final byte SNDBUF
See Also:
Constant Field Values

READ_WRITE

public static final int READ_WRITE
See Also:
Constant Field Values
Constructor Detail

SocketAdapter

public SocketAdapter(java.lang.String host,
                     int port,
                     int mode,
                     boolean timeout)
              throws java.io.IOException
Creates a FileAdapter instance, opening the underlying SocketConnection.

Parameters:
server - is the remote server (without protocol specification)
port - is the remote port
Throws:
java.io.IOException - if the connection cannot be established
Method Detail

openInputStream

public java.io.InputStream openInputStream()
                                    throws java.io.IOException
Open and return an input stream for this Socket.

Throws:
java.io.IOException

openOutputStream

public java.io.OutputStream openOutputStream()
                                      throws java.io.IOException
Open and return an output stream for this Socket.

Throws:
java.io.IOException

close

public void close()
           throws java.io.IOException
Close this Socket

Throws:
java.io.IOException

setSocketOption

public void setSocketOption(byte option,
                            int value)
                     throws java.io.IOException
Throws:
java.io.IOException


Copyright © 2001-2009 Funambol.